GitHub CLI
GitHub CLI is a useful program for performing GitHub specific operations without leaving your shell. While it
encapsulates many standard Git operations, I tend to only use GitHub CLI for the capabilities I cannot replicate
from the git
command. One step everyone needs to complete to utilize tools like the GitHub CLI is
to set up the program in your environment. While GitHub provides plenty of documentation to accomplish this, I
have recently been using the Nix Package Manager combined with Nix Home Manager to manage the applications I
install on my machine.
Nix Home Manager
Nix Home Manager is a tool in the Nix ecosystem used for managing installation of packages and their
configuration from a singular configuration file written in the Nix Language. While Nix is a large (and
complicated) ecosystem to navigate for beginners, I have found it's package management to be beneficial to my own
workflow. On my personal device, I use a standalone installation of the Nix Home Manager. This is perfect for my
use case since I have not bothered to migrate to NixOS for my operating system. Currently, I am running Ubuntu
24.04. Once installed, I only need to alter my home.nix
file stored in my
~/.config/home-manager/
directory.
This can be accomplished by running the command home-manager edit
which opens your
home.nix
file with your default editor. The configurations are not something you can guess. While
documentation is available online, the best resource is the home-configuration.nix manual page.
Once in the manpage, I simply type "/" to enter the search and search for "programs\.gh\." to quickly navigate to
the documentation for configuring GitHub CLI.
The configuration I added to enable this program was simply programs.gh.enable = true;
to
enable Home Manager to install and manage the GitHub CLI application. Once the configuration is added, Nix/Home
Manager does not automatically apply your changes, you need to execute home-manager switch
to apply
the changes so that they take effect. There is a lot more happening under the hood which I will not get into with
this post, but Nix is an interesting package manager and I'd encourage anyone to look into it.
Authenticating GitHub CLI
With GitHub CLI installed, you still need to authenticate. I'm no expert on this subject, so I'll simply tell you
what I did to get up and running. To check that gh
was available, I just use type gh
.
The output should be the path to the gh
executable in your path (or a symbolic link). After that, I
executed gh auth login
to start the authentication process to GitHub. You need to follow the prompts
to get it configured and if anything is unclear, seek out the docs from GitHub.
Using GitHub CLI
To put it to good use, I decided to make a private gist on GitHub to store my home.nix
file so that
I can reproduce my configuration on other systems. To accomplish that, I found the file and used the command
gh gist create ~/path/to/home.nix --desc "Description for my Gist"
. With that completed, I have a
backup of my Home Manager configuration stored in GitHub that I can pull down onto other machines or update
periodically. I find with how much time system configuration can take when you start on a new machine, finding a
way to replicate your setup is time worth spending.