How to Install and Use Github Cli?

github
Reading Time: 3 minutes

Do you ever imagine that you can manage your pull requests or issues directly from CLI instead of Ui, I know if you are someone who loves working with the command line might be bored using UI for GitHub. Thanks to the GitHub Cli through which you can manage all these tasks in the command line.

In this blog, we will be looking at the installation of GitHub cli and along with that we will see how we can use the cli to manage our GitHub, However, I am sure by the end of this blog you will have a basic understanding of GitHub cli. So let’s get started.

With Github Cli we can Interface directly with our Repositories without ever having to leave the command line. The reason that makes this much better is that without having to jump between the terminal and the browser there’s less context switching involved in our day-to-day work.

Installing Github Cli or gh on ubuntu

 curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh

If you are using anything else other than ubuntu, You can visit this for installation.

Authentication

Now let’s look at the basic usage of the GitHub cli

The first thing we will do is authenticate our account which we can do with this command.

gh auth login

When you press enter it will ask you to choose from

  1. Github.com
  2. Github Enterprise Server

In my case, I will choose the First option after you will be asked t choose the preferred protocol i.e either HTTPS or SSH, You can choose any and In my case, I choose HTTP.

So, Later I was asked to select the method through which I want to authenticate either log in with a web browser or paste an authentication token enter the authentication token.

I chose to paste the token and was successfully authenticated, you can choose any method.

Github Cli

Now you can interact with GitHub cli and do the tasks that you were doing with UI and if you type check the help command you can find the commands that you can perform with the GitHub cli.

help

Forking and Cloning Repo directly with Cli

Now let’s take an example where we will fork and clone the official ansible repository with the help Cli

gh repo fork ansible/ansible  --clone
Fork

You learned to fork with this method now to check if it is cloned or not, go to the folder. I would like to add this doesn’t replace git. You can use git normally as you were doing. The thing is that we are adding Github Cli on top of it So as to do the task on the command line that we were doing with UI. So, you can use this for issues, PR, and much more.

Conclusion

This was all about a basic Understanding of using Github Cli. I showed you how you can install this on your machine. In addition to this, We further looked into the authentication part and ended with a basic example of forking and cloning a repository with the help of this cli. To Learn More about this Cli you can visit this Documentation.

References

All the References are taken from official Documentation.

knoldus

Written by 

Passionate about Technology and always Interested to Upskill myself in new technology, Working in the field of DevOps