Getting Started with GitHub Cli — A Beginner Guide
GitHub CLI brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git and your code.
Installation
Step 1
GitHub CLI works with Git therefore we need to install Git on the computer. Git is used internally for some functions like Cloning, Merging, pulling and pushing, etc.
You can download and install Git from this website https://git-scm.com/downloads According to your systems requirements.
Step 2
Next, Download Latest GitHub CLI From GitHub Official Website https://github.com/cli/cli/releases
Scroll down and download GitHub CLI According to your Operating systems.
Authentications
Step 1:
First, we need to Authenticate GitHub CLI with GitHub Account. if you don't have a GitHub Account You can create your GitHub in a few minutes. https://github.com/join
Step 2 :
Secondly, Open Command Shell(CMD) and Run
gh auth login
If you have a GitHub Enterprise Server for your organizations you can go with the second option. I have a GitHub account so I will Auth my account with Github.com
Step 3:
Select the Login with a web browser option and press the Enter Key. Make Sure you Copy your on-time code.
Step 4:
Next, You need to copy the one-time code and paste it into the GitHub CLI Authentication page on your browser. After this You need to Authorized your GitHub Account with GitHub. Just Click on Authorize Github and Enter your password on the next screen.
Step 5:
Boom! You are all set and good to go.
Step 6:
When you go back to your Command Prompt GitHub CLI will ask you about the Default git protocol so choose HTTPS because of simplicity.
Finally! You have Authenticated your GitHub Account with GitHub CLI. Let's have a Hand-on on GitHub CLI.
Cloning & Creating New Repo
Cloning a Repo From GitHub
gh repo clone <REPO LINK>e.g gh repo clone https://github.com/adilshehzad786/test
As you can see, gh gracefully cones the repo and creates its folder in my directory. Now run cd followed by the name of the repo to enter its folder.
cd test
by Running the command we can have a list of files insides the local repository
Creating a Repo on GitHub Using GitHub CLI
Let's create a Repo on GitHub Using GitHub CLI. The Most Coolest Feature is that while creating Repo on GitHub. GitHub CLI also creates Repo on the l machine.
gh repo create [name]
Replace [name] with your actual Repo name.
On GitHub
Let's add a README.MD file and push into the testmediumblog repository.
git status
git add README.md
git commit -m " Adding a README.md file which contain author informations"
Incase you are getting error: failed to push some refs to then enter this command first git branch -M mainand then this onegit push -u origin main
Conclusion
With the help of GitHub CLI, we can control GitHub using the Command Shell Prompt. We can Create Repo, Delete Repo, Create a pull Request, Create an Issue on Github, and Much more. Refer to this complete Manual here