How to use the GitHub CLI app on Windows and WSL
Microsoft-owned GitHub is the biggest code-sharing platform on the planet and while using it through the web browser is simple, when you’re interacting with your code and local files you’re more than likely using a terminal.
That’s where GitHub CLI comes in. An official tool made by GitHub, it’s good to use both on Windows 10 and Windows 11 in PowerShell or within the Windows Subsystem for Linux (WSL). Once you’re familiar with it, it could speed up a number of areas of your GitHub workflow.
Here’s how to install it, get set up and carry out some basic processes.
Set up a GitHub account before anything else
Source: GitHub
A GitHub account also allows you to make use of the oft-overlooked GitHub CLI terminal application, which due to some changes in how GitHub allows accounts to be authenticated, is actually something you should have. More on that later.
You don’t have to interact with GitHub through the terminal, but in many cases, it’s the most efficient workflow.
Installing GitHub CLI onto Windows or WSL
Source: Windows Central
To install the GitHub CLI on Windows you can use the Windows Package Manager again by entering winget install github.cli
, or grab it directly from GitHub. Alternatively, it’s available through the Scoop and Chocolately package managers, too, where you’ll simply need to install gh
.
On WSL, the process is a little more involved, but GitHub has full documentation you can follow. Since most people using WSL are likely to have Ubuntu or Debian installed as they’re officially distributed through the Microsoft Store, you can use the following commands in your WSL terminal to install it.
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
As with Git, the WSL installation of the GitHub CLI is separate from the Windows installation you would use in PowerShell. The two operate the same way, but if you switch between WSL and PowerShell you’ll need to have it installed in both locations.
How to set up GitHub CLI and authenticate your account
The GitHub CLI, unlike Git, can use your account login and password for authentication with the added bonus of then also allowing Git to push to your GitHub repositories. To authenticate GitHub CLI, open up your terminal and follow these steps. Again, all the steps are the same whether you use Windows or WSL.
- In the terminal enter
gh auth login
- Choose GitHub.com.
- Select HTTPS as the protocol.
Source: Windows Central
- Type Y to authenticate with your GitHub credentials
- Hit Enter to login with a web browser.
Source: Windows Central
- Note down the one-time code you’re presented with, and press Enter.
- A browser will now open, and you’ll need to log into GitHub if you aren’t already.
- Enter the one-time code in the box.
You’ll now be logged into the GitHub CLI client. To see the full list of commands available simply type gh --help
into the terminal.
Using GitHub CLI
There is a basic command template for using GitHub CLI that looks like this:
gh [command] [sub-command] [flags]
All commands you enter will begin with gh
in order to trigger GitHub CLI. There are a number of commands to use, but here are some examples of how you would carry out some basic functions.
Create a new GitHub repository
Source: Windows Central
gh repo create
You’ll be asked to give it a name, an optional description, its visibility and to confirm you want to create an “origin” Git remote in your local directory. Once all are completed, you can go check out your new repo on the GitHub website. You can open up this or any of your other GitHub repos from their local directories by entering gh browse
into the terminal.
Clone or fork a GitHub repository
Source: Windows Central
git clone
command to clone a local copy of a GitHub repository, but you can do the same using the GitHub CLI tool using this command.
gh repo clone [user/repo name or URL]
So for example, to clone Microsoft Visual Studio you would simply enter:
gh repo clone microsoft/vscode
Source: Windows Central
gh repo clone [your repo name]
Source: Windows Central
gh repo fork [user/repo name or URL]
For example:
gh repo fork microsoft/winget-pkgs
Once you hit Enter, you’ll be asked whether you want to clone the fork or not, with a simple y
or n
being all you need to enter.
Source: Windows Central
gh repo list microsoft
Creating a new issue
Source: Windows Central
gh issue create
The tool will then ask you to give your issue a title, followed by opening a text editor, such as Nano in WSL, to fill out the body of the issue, then the option to submit or to continue in the browser. It’s really straightforward, and the prompts will guide you at every step.
Viewing and closing issues
Source: Windows Central
issue
command type gh issue --help
into the terminal. One of the most common you’ll want to use is viewing issues and then closing them if dealt with.
To view all issues for your GitHub repository enter this command.
gh issue list
Source: Windows Central
gh issue close 1
You’ll be given a confirmation that the issue has closed, and to confirm you can run the list command again, and it should be gone.
Creating a pull request
Source: Windows Central
gh pr create [subcommand]
At any time you can add --help
to the above to get a full breakdown of all available options. If you wanted to create a pull request and continue it on the web, for example, you would enter:
gh pr create -w
Pull requests behave in exactly the same way as on the web, so naturally won’t work if you’re on the master branch.
If at any point you need a bit more information, the --help
flag after a command is your friend, as it’ll break down everything you can do with every possible command available in GitHub CLI.
Here’s everything announced during The Game Awards 2021
The Game Awards 2021 may have been celebrating some of the best parts of video games in 2021, but it also gave us a look at what’s to come in the future. Here’s everything announced during The Game Awards 2021.