Github Cli
GitHub CLI
The GitHub CLI or gh
is basically GitHub on command-line.
You can interact with your GitHub account directly through your command line and manage things like pull requests, issues, and other GitHub actions.
In this tutorial, I will give a quick overview of how to install gh
and how to use it!
GitHub CLI Installation
As I will be using Ubuntu, to install gh
you need to run the following commands:
If you are on a Mac, you can install gh
using Homebrew:
For any other operating systems, I recommend following the steps from the official documentation here.
Once you have gh
installed, you can verify that it works with the following command:
This would output the gh
version:
In my case, I’m running the latest gh
v1.0.0, which got released just a couple of days ago.
Authentication
Once you have gh
installed, you need to login to your GitHub account.
To do so, you need to run the following command:
You will see the following output:
You have an option to choose between GitHub.com or GitHub Enterprise. Click enter and then follow the authentication process.
Another useful command is the gh help
command. This will give you a list with the available gh
commands that you could use:
Then let’s clone an existing project which we will use to play with. As an example, we can use the LaraSail repository. Rather than cloning the repository using the standard git clone
command, we will use gh
to do so:
You will see the following output:
After that cd
into that folder:
We are now ready to move to some of the more useful gh
commands!
Useful GitHub CLI commands
Using gh
, you can pretty much get all of the information for your repository on GitHub without having even to leave your terminal.
Here’s a list of some useful commands:
Working with GitHub issues
To list all open issues, run:
The output that you will see is:
You can even create a new issue with the following command:
Or if you wanted to view an existing issue, you could just run:
This would return all of the information for that specific issue number:
Working with your GitHub repository
You can use the gh repo
command to create, clone, or view an existing repository:
For example, if we ran the gh repo view
, we would see the same README information for our repository directly in our terminal.
Working with Pull requests
You can use the gh pr
command with a set of arguments to fully manage your pull requests.
Some of the available options are:
With the above commands, you are ready to execute some of the main GitHub actions you would typically take directly in your terminal!
Conclusion
Now you know what the GitHub CLI tool is and how to use it! For more information, I would recommend checking out the official documentation here:
https://cli.github.com/manual/
I’m a big fan of all command-line tools! They can make your life easier and automate a lot of the daily repetitive tasks!
Initially posted here: What is GitHub CLI and how to get started