gh + git + terminal = superpower

solomon

You're probably a developer reading this blog and like every developer, we spend almost all time in the terminal unless you're just starting out

And one thing we all developers love most is productivity, cause why not, we tend to be more productive when have the right tools and in the right state of mind which the tool(s) contribute to still

Github gh

github gh is a github command line tool that enhances productivity by bringing the beauty of github web interactions right in to your development enviroment, so no hassle of going to the github web app to do the things we normally go to do which some examples are

  • To create pull request
  • To merge pull request
  • To create issues
  • To create a repo and so on

How do we use this power

To get a full taste of this power/tool we first need to install it on our terminal, but before installing it's always better to have git installed first

To check if you have git installed run these commands

git --version

This commands work for both linux and macOS if you see an an output like this

git version 2.45.2

you're good to continue

Now let's install gh by visiting this link or viewing the commands below as i will explain everything below, while still in your terminal type

brew install gh # for mac users
(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 # for linux(debian users)

this command will go ahead and install gh in our respective enviroments and after that let's set it up!

Setup

let's authenticate and connect our gh to our github account by running these commands

gh auth login

we will be prompted to set our preffered method of authentication, i go with normal github not enterprise, then i choose ssh as my preferred protocol for Git operations, then passphrase for the ssh key which optional, then title for the generated ssh key, then choose how you want to authenticate that is connect to github web app, which i choose login with a web browser, you'll be given a unique 8 alphanumric code separated with a dash example is this

EA72-7B52

which i will copy then press enter to open the tab automatically on my default browser which i will paste the code the authorize

if you run into issue in opening the tab automatically like this

! Failed opening a web browser at https://github.com/login/device
  exec: "xdg-open,x-www-browser,www-browser,wslview": executable file not found in $PATH
  Please try entering the URL in your browser manually

you just need to copy the link manually and paste in your browser, here is the link then authenticate and the will see a success tab that says "SUCCESS" or something like that

Test Example

let's test gh by using it to clone a repo

syntax

gh repo clone githubUsername/repoName

this command will clone the repo to our local machine

that's it for this post, checkout other post as i will be posting tips that help me daily here!