DEV Community

Cover image for 🚀 Begginer's Guide: installing and using GitHub CLI 🛠️
Raúl Peñate
Raúl Peñate

Posted on

🚀 Begginer's Guide: installing and using GitHub CLI 🛠️

Why use GitHub CLI?

GitHub CLI brings GitHub to your terminal. It allows you to clone, create, fork, and view repositories, as well as handle issues and pull requests with commands to list, create, view, and merge them. You can also manage gists, trigger and review GitHub Actions workflows, and make direct API requests. You also have authentication and configuration options are available to manage access and settings, while search functionalities help you find repositories, issues, and more.


Part 1: Install GithubCLI 🔨

macOS 🍎

gh is available via Homebrew, MacPorts, Conda, Spack, Webi, and as a downloadable binary including Mac OS installer .pkg from the releases page.

# Homebrew
brew install gh

# MacPorts
sudo port install gh

# Conda
conda install gh --channel conda-forge

# Spack
spack install gh

# Webi
curl -sS https://webi.sh/gh | sh
Enter fullscreen mode Exit fullscreen mode

Windows 🪟

gh is available via WinGet, scoop, Chocolatey, Conda, Webi, and as MSI installer.

# WinGet
winget install --id GitHub.cli

# scoop
scoop install gh

# Chocolatey
choco install gh

# Conda
conda install gh --channel conda-forge

# Spack
spack install gh

# Webi
curl -sS https://webi.sh/gh | sh
Enter fullscreen mode Exit fullscreen mode

Linux 🐧

Here it really depends what you're using, here can you read the linux install documentation to find what you need, or check here the commands depending the distro you're using.

# Arch
sudo pacman -S github-cli

# Debian, Ubuntu Linux, Raspberry Pi OS (apt)
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/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 -y
# Upgrade
sudo apt update
sudo apt install gh

# Fedora, CentOS, Red Hat Enterprise Linux (dnf)
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh --repo gh-cli
#Alternatively, install from the community repository:
sudo dnf install gh
#Upgrade
sudo dnf update gh

# openSUSE/SUSE Linux (zypper)
sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo
sudo zypper ref
sudo zypper install gh
# Upgrade
sudo zypper ref
sudo zypper update gh
Enter fullscreen mode Exit fullscreen mode

Part 2: Log in 🔐

First write in your terminal:

gh auth login
Enter fullscreen mode Exit fullscreen mode

Here will ask you:

? What account do you want to log into?  [Use arrows to move, type to filter]
> GitHub.com
  GitHub Enterprise Server
Enter fullscreen mode Exit fullscreen mode

If you choosed Github.com it will ask you:

? What is your preferred protocol for Git operations on this host?  [Use arrows to move, type to filter]
> HTTPS
  SSH
Enter fullscreen mode Exit fullscreen mode

Next it'll ask you your protocol and personal preference I recommend SSH.

? What is your preferred protocol for Git operationInstall Github CLI in Linuxs on this host?  [Use arrows to move, type to filter]
  HTTPS
> SSH
Enter fullscreen mode Exit fullscreen mode

Now just create the password for your SSH Key, the title and select how you'd like to autheticate, and if this is your first time just use Login with a web browser.

? Generate a new SSH key to add to your GitHub account? (Y/n) Y

 Enter a passphrase for your new SSH key (Optional): **************************

? Title for your SSH key: (GitHub CLI) TheMachine-Desktop

? How would you like to authenticate GitHub CLI?  [Use arrows to move, type to filter]
> Login with a web browser
  Paste an authentication token

! First copy your one-time code: 1234-ABCD
Press Enter to open github.com in your browser... 
Enter fullscreen mode Exit fullscreen mode

🎉 Congratulations 🎉, now you can use Github from your terminal 🖥️.! if you write gh auth status, you should get something like this:

$ gh auth status
github.com
   Logged in to github.com account username (/home/username/.config/gh/hosts.yml)
  - Active account: true
  - Git operations protocol: ssh
  - Token: ...
  - Token scopes: ....
Enter fullscreen mode Exit fullscreen mode

Part 3: Useful commands 📝

Here I'll give you ⭐My TOP 5 commands in Github CLI🏅 so you can build an idea of what you are capable of doing, but feel free to checkout the documentation to gain a deeper knowledge of this tool.

1 - Clone a GitHub repository 🥇: gh repo clone owner/repo

gh repo clone chrislgarry/Apollo-11
Enter fullscreen mode Exit fullscreen mode

Bonus 🎁:
Since you're using ssh you can also go to this section of a GitHub repo:

Showing Github repo, the tab where you can select http, ssh or github cli
And git clone it like this:

git clone git@github.com:chrislgarry/Apollo-11.git
Enter fullscreen mode Exit fullscreen mode

And you can view the README.md of the repo:

 gh repo view chrislgarry/Apollo-11
Enter fullscreen mode Exit fullscreen mode

Terminal showing github description
2 - Create a new repository on GitHub 🥈: gh repo create repo, you can use flags like --public, private, --description <string> and more.

gh repo create my-new-repo --public
Enter fullscreen mode Exit fullscreen mode

3 - Create a new gist 🥉: gh gist create <file>

gh gist create file.txt
Enter fullscreen mode Exit fullscreen mode

Bonus 🎁:
You can also list them:

gh gist list
Enter fullscreen mode Exit fullscreen mode

4 - Create a new issue 🏅: gh issue create --title <title> --body <body>

gh issue create --title "Issue title" --body "Issue body"
Enter fullscreen mode Exit fullscreen mode

Bonus 🎁:
You can alse create issues:

gh issue create --title "Issue title" --body "Issue body"
Enter fullscreen mode Exit fullscreen mode

view issues:

gh issue view <issue-number>
Enter fullscreen mode Exit fullscreen mode

And close issues:

gh issue close <issue-number>
Enter fullscreen mode Exit fullscreen mode

5 - List pull requests 🌟: gh pr list

gh pr list
Enter fullscreen mode Exit fullscreen mode

Bonus 🎁:
You can also view the pull request:

gh pr view <pr-number>
Enter fullscreen mode Exit fullscreen mode

merge a pull request:

gh pr merge <pr-number>
Enter fullscreen mode Exit fullscreen mode

And review it:

gh pr review --approve --body "Looks good!"
Enter fullscreen mode Exit fullscreen mode

Final Thoughts 🎉

GitHub CLI brings GitHub to your terminal, making it incredibly powerful! 🚀 I hope you found this post helpful and that it has inspired you to make the most of this tool. Don’t forget to subscribe for more updates for my future post! 🙌🖥️


Sources 📚

Install Github CLI
Install Github CLI in Linux
Github CLI manual
Apollo 11 Code


Here I'd like to add a personal phrase, but I'm still thinking/looking for one 😂

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more