š 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
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
A GitHub Account
Ensure you have an active GitHub account.
š¦ Step-by-Step Guide
- 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.
- 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:
bash
Copy code
mkdir my-project
cd my-project
- Initialize Git If you havenāt initialized a Git repository in your project folder, do so now:
bash
Copy code
git init
- Create the GitHub Repository Use the GitHub CLI to create a new repository:
bash
Copy code
gh repo create <repository-name>
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
- Stage and Commit Your Files Stage all files for commit:
bash
Copy code
git add .
Create your first commit:
bash
Copy code
git commit -m "Initial commit"
- 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
ā
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>
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! š
Top comments (0)