DEV Community

Cover image for How to Create a GitHub Repository from your Terminal
Muhammad Arif Raza
Muhammad Arif Raza

Posted on

How to Create a GitHub Repository from your Terminal

🚀 How to Create a GitHub Repository from Your Terminal
GitHub is a developer’s best friend when it comes to version control and collaboration. While most people use the GitHub web interface to create repositories, did you know you can do it faster directly from your terminal? Whether you're a seasoned developer or just getting started, this guide will show you how to create a GitHub repository straight from the command line using the GitHub CLI.

🛠 Prerequisites
Before diving in, make sure you have the following tools ready to go:

Git Installed

Check if Git is installed:

bash
Copy code
git --version
Enter fullscreen mode Exit fullscreen mode

If not, download and install it from git-scm.com.
GitHub CLI (gh) Installed

Download the GitHub CLI from cli.github.com.
After installation, verify it by running:

bash
Copy code
gh --version
Enter fullscreen mode Exit fullscreen mode

A GitHub Account

Ensure you have an active GitHub account.
🚦 Step-by-Step Guide

  1. Authenticate with the GitHub CLI Log in to GitHub from your terminal:
bash
Copy code
gh auth login
Follow the on-screen instructions to authenticate via your browser or terminal.
Enter fullscreen mode Exit fullscreen mode
  1. Navigate to Your Project Directory If you already have a project folder, move into it:
bash
Copy code
cd /path/to/your/project
If not, create a new directory:
Enter fullscreen mode Exit fullscreen mode
bash
Copy code
mkdir my-project  
cd my-project 
Enter fullscreen mode Exit fullscreen mode
  1. Initialize Git If you haven’t initialized a Git repository in your project folder, do so now:
bash
Copy code
git init 
Enter fullscreen mode Exit fullscreen mode
  1. Create the GitHub Repository Use the GitHub CLI to create a new repository:
bash
Copy code
gh repo create <repository-name>
Enter fullscreen mode Exit fullscreen mode

Replace with your desired repo name. You’ll be prompted to select:

Visibility: Public or Private
Location: In the current directory or as a blank repo
For example, to create a public repository in your current folder, run:

bash
Copy code
gh repo create my-awesome-project --public
Enter fullscreen mode Exit fullscreen mode
  1. Stage and Commit Your Files Stage all files for commit:
bash
Copy code
git add . 
Enter fullscreen mode Exit fullscreen mode

Create your first commit:

bash
Copy code
git commit -m "Initial commit"  
Enter fullscreen mode Exit fullscreen mode
  1. Push Your Code to GitHub Push your local code to the newly created remote repository:
bash
Copy code
git branch -M main  
git push -u origin main  
Enter fullscreen mode Exit fullscreen mode

✅ Verify Your Repository
Head over to GitHub and check your profile or organization to see your new repository live!

💡 Bonus Tips
To create repositories for a specific GitHub organization, use:

bash
Copy code
gh repo create <repository-name> --org <organization-name> 
Enter fullscreen mode Exit fullscreen mode

Use gh repo view to quickly view repository details from your terminal.

Automate your workflow by combining these steps into a shell script.

🚀 Conclusion
Creating a GitHub repository from your terminal is quick, efficient, and keeps you in your flow. Tools like the GitHub CLI make managing repositories a breeze. Whether you’re starting a new project or migrating an existing one, this method saves time and keeps things simple.

Do you have other tips for managing GitHub repositories? Let me know in the comments below!

Happy coding! 🎉

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay