How to Create a GitHub Repository from your Terminal
Learn how to create and manage GitHub repositories directly from your terminal using the GitHub CLI tool
Managing GitHub repositories from your terminal can significantly enhance your development workflow. By using the command line, you can quickly create and initialize repositories, manage commits, and push changes without relying on a graphical interface. This guide will take you step-by-step through the process, making it easy to harness the power of Git and GitHub directly from your terminal.
Install GitHub CLI
GitHub CLI , or gh, is an open-source command-line interface to GitHub for use in your terminal or your scripts. You need to install it into your PC to start using it. Visit the link above to download and install it into your machine.
Create a New Repository
Open up a terminal and run the below command to create a new repository
terminal
gh repo create
This will prompt an interactive window you can use to configure your repository details.
terminal
What would you like to do? Create a new repository on GitHub from scratch
? Repository name test
? Repository name test
? Repository owner Avdhesh-Varshney
? Description Testing GitHub CLI
? Description Testing GitHub CLI
? Visibility Public
? Would you like to add a README file? Yes
? Would you like to add a .gitignore? Yes
? Would you like to add a license? Yes
? This will create "test" as a public repository on GitHub. Continue? Yes
ā Created repository Avdhesh-Varshney/test on GitHub
https://github.com/Avdhesh-Varshney/test-cli
? Clone the new repository locally? No
Once completed, you should have your repository successfully created on GitHub. Now you can point your local project to the remote branch and push it to GitHub.
terminal
git remote add origin https://github.com/Avdhesh-Varshney/test.git
git add .
git commit -m 'Initial commit'
git push origin main
If you choose to create a README or LICENSE file during the gh repo create set-up, trying to pull it into a local project will obviously throw an error due to unrelated histories between the remote and local branch.
To resolve this, you can force the merging using the below command:
terminal
git pull origin main --allow-unrelated-histories
If you get any conflicts, simply fix it, commit and then push to GitHub.
Aside form creating a new repository, you can perform other operations using the GitHub CLI tool.
To see more, visit the GitHub CLI Commands documentation.
Comments