Github CLI: An Introduction
Streamline your workflow with Github CLI: an introduction to the gh command line tool
Github, earlier this year, introduced the beta version of its latest tool, Github CLI
, which is aimed at developers. The tool has been designed to aid in reducing context switching while enabling developers to run their complete workflow directly from the terminal.
It is a novel concept that is receiving a lot of attention and has already proven to be incredibly useful in the field of development. #LetsTalkAboutIt.
Scenario
Using the Git terminal, you stage, commit and push modifications to your remote repository in your local repository. After completing this process, you switch to the Github web interface for tasks such as pull requests, issue tracking, and other duties.
This cycle can be repeated up to fifty times a day or more, adding to the already stressful nature of coding and debugging. The sheer volume of tasks to complete can be overwhelming.
Enter Github CLI
The good news is that Github CLI offers a remedy to this predicament. With Github CLI, you can handle all of the web-related duties and much more without having to switch to the browser. Furthermore, you gain access to an API that can be customized to your preferences. Let's delve into the world of Github CLI and learn how to use gh
Installation
The installation instructions for Github CLI are comprehensively detailed in the README file. It is imperative to follow these guidelines to ensure a successful installation.
Windows
You can download the MSI installers for Github CLI from the releases page. These installers provide a straightforward method of installing the application. Simply locate the appropriate installer for your operating system and follow the installation instructions.
# Via Scoop
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
# Via Chocolatey
choco install gh
Mac OS
# Via Homebrew
brew install gh
# Via MacPorts
sudo port install gh
Linux
# Debian, Ubuntu Linux (apt)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
If you're using a Linux distribution other than Debian or Ubuntu, you can visit the Github CLI install instructions page.
There, you will find detailed instructions on how to install the application on different Linux distributions, including Ubuntu, Debian, CentOS, Fedora, and others. Make sure to follow the guidelines carefully to ensure a successful installation.
Getting Started
After installing Github CLI, it is essential to check the version to ensure that it has been installed correctly. You can do this by typing the following command in your terminal:
gh version
If Github CLI has been installed successfully, you will receive a response similar to the following:
gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0
Authentication
Github CLI offers a smooth authentication process. When you first attempt to use a command that requires authentication, you will be prompted to select between Github and Github Enterprise.
gh auth login
You will then be given the option to authenticate through a web browser or paste a Github token. If you have already set a GITHUB_TOKEN environment variable, Github CLI will automatically use it. This process ensures a seamless and straightforward authentication experience.
Commands
Github CLI commands are designed to be simple, straightforward, and easy to understand and use. The command-line interface provides an intuitive syntax that makes it easy to perform various tasks such as creating and managing pull requests, issues, repositories, and more.
Additionally, Github CLI provides an extensive help system that offers detailed documentation on each command and its syntax. With its user-friendly interface and thorough documentation, Github CLI offers an efficient way to manage your Github workflow from the terminal.
gh help
Work seamlessly with GitHub from the command line.
USAGE
gh <command> <subcommand> [flags]
CORE COMMANDS
gist: Create gists
issue: Manage issues
pr: Manage pull requests
release: Manage GitHub releases
repo: Create, clone, fork, and view repositories
ADDITIONAL COMMANDS
alias: Create command shortcuts
api: Make an authenticated GitHub API request
auth: Login, logout, and refresh your authentication
completion: Generate shell completion scripts
config: Manage configuration for gh
help: Help about any command
FLAGS
--help Show help for command
--version Show gh version
EXAMPLES
$ gh issue create
$ gh repo clone cli/cli
$ gh pr checkout 321
ENVIRONMENT VARIABLES
See 'gh help environment' for the list of supported environment variables.
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
FEEDBACK
Open an issue using 'gh issue create -R cli/cli'
repo
The repo
subcommand in Github CLI allows you to create, clone, view, and manage repositories. Here are some examples of how to use the repo
subcommand:
To create a new repository, use the
gh repo create
command. For example:gh repo create my-new-repo
To clone a repository, use the
gh repo clone
command. For example:gh repo clone owner/repo-name
To view information about a repository, use the
gh repo view
command. For example:gh repo view owner/repo-name
To list your repositories, use the
gh repo list
command. For example:gh repo list
To delete a repository, use the
gh repo delete
command. For example:gh repo delete owner/repo-name
These are just a few examples of the commands available in the repo
subcommand. As mentioned earlier, Github CLI offers detailed documentation for each command, which you can access using the --help
flag. For example: gh repo create --help
.
alias
The alias
subcommand allows you to create aliases for any Github CLI command. Aliases are custom shortcuts that you can use to simplify and speed up your workflow. Here are some examples of how to use the alias
subcommand:
To create a new alias, use the
gh alias set
commandgh alias set il 'issue list' # - Adding alias for il: issue list # ✓ Added alias.
To list your current aliases, use the
gh alias list
command.gh alias list # il: issue list
To remove an alias, use the
gh alias delete
command. For example:gh alias delete il
These are just a few examples of how to use the alias
subcommand. You can create aliases for any Github CLI command, which can save you time and reduce typing errors. As with all Github CLI commands, you can access detailed documentation for the alias
subcommand by using the --help
flag. For example: gh alias set --help
.
Github CLI provides many other subcommands that can help you manage your Github workflow more efficiently. Here are a few examples of some of the other subcommands available:
The
issue
subcommand allows you to create, view, and manage issues.The
pr
subcommand allows you to create, view, and manage pull requests.The
gist
subcommand allows you to create, view, and manage gists.The
workflow
subcommand allows you to create, view, and manage Github Actions workflows.The
secret
subcommand allows you to manage secrets for your Github repositories.The
config
subcommand allows you to configure various settings for Github CLI.
Each subcommand provides a comprehensive set of features and options, and the Github CLI documentation website provides detailed information on how to use each subcommand effectively.
Conclusion
Indeed, Github CLI is very well documented, providing a rich user experience. In addition to the extensive help system available within the command-line interface, Github CLI also provides a comprehensive documentation website.
The website contains detailed information on how to install and configure Github CLI, as well as comprehensive documentation on each command and its syntax.
The documentation website also includes examples, FAQs, and troubleshooting tips to help you get the most out of Github CLI. Whether you're a seasoned developer or just getting started with Github, the documentation website is an invaluable resource for using Github CLI effectively.