Creating a GitHub Repository Using gh
- This guide explains two ways to create a repository on GitHub using GitHub CLI (
gh).
Prerequisites
- A GitHub account (Sign up here if you don’t have one)
- GitHub CLI (
gh) installed - Git installed (Download here)
- Authentication with
gh auth login
Task: Create a new GitHub repository
1. Authenticating with (gh)
- Open your terminal and authenticate if you haven’t already.
-
Execute the following and follow the prompts to log in via browser or SSH key.
### Authenticating with GitHub CLI ## You should see prompts like these: ? Where do you use GitHub? GitHub.com ? What is your preferred protocol for Git operations on this host? SSH ? Upload your SSH public key to your GitHub account? /Users/xxxx/.ssh/id_rsa.pub ? Title for your SSH key: GitHub CLI ? How would you like to authenticate GitHub CLI? Login with a web browser ! First copy your one-time code: XXXX-XXXX Press Enter to open https://github.com/login/device in your browser...
2. Create a new repository:
-
Create a new repository using the following command:
-
You should see output like this:
3. Verify creation:
-
Validate the repository creation:
-
This should open your new repository in your browser.