search
HomeTechnology peripheralsIt IndustryGitHub CLI: A Guide to GitHub from the Command Line

GitHub CLI Quick Start Guide: Say goodbye to the browser and control your GitHub on the command line

This article will take you to quickly get started with the GitHub CLI to understand its uses, settings and usage methods.

If you are familiar with Git commands, you must know that you need to switch to a web browser to perform various operations on your GitHub repository. The new GitHub CLI tool allows you to perform many of these operations without leaving the command line interface.

Core points

  • GitHub CLI allows users to perform various operations on the GitHub repository without leaving the command line interface without switching to a web browser.
  • GitHub CLI command structure is similar to a tree and contains two layers: the first layer contains six commands: config, repo, issue, pr, gist, credits,
  • , and
  • . Each command has a second layer where the user can specify the action to perform.
  • GitHub CLI allows users to clone, fork, view, and create repositories directly from the command line. It also includes commands for creating and managing pull requests, issues, and gist.
While the GitHub CLI is a powerful GitHub repository management tool, it is important to note that it is still under development and new commands may appear over time. It is recommended that the user refer to the manual for new features and how to use existing tools.

GitHub CLI Settings

To get started, simply visit the installation page and find the GitHub CLI installation instructions for your operating system. For Windows and macOS, you can use the package manager to install and update the GitHub CLI. For Linux users, the package needs to be downloaded from the latest release page. Windows users also have a signed MSI installer, but please note that if you choose this method, you must manually re-download and update the tool. For Windows users, the easiest way is to use the scoop package manager.

    The following are the installation instructions for each supported platform:
Windows:
<code>scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh</code>
macOS:
<code>brew install gh</code>
Debian/Ubuntu Linux:
<code>sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb</code>
Fedora/Centos Linux:
<code>sudo yum localinstall gh_*_linux_amd64.rpm</code>
Arch Linux:
<code>yay -S github-cli</code>

On Windows, I recommend using a Git Bash terminal. This interface will allow you to access commonly used Linux commands and Bash functions, such as automatic completion. It is also officially supported by Visual Studio Code through terminal integration. gh repo view cli/cli

After installing the GitHub CLI, you need to verify your account. Running any command will trigger this authentication process. For example, try

. For users who use it for the first time, the system will prompt you: GitHub CLI: A Guide to GitHub from the Command Line

Simply press the

Enter

key to start the process as follows: GitHub CLI: A Guide to GitHub from the Command Line

After providing the password, you will receive a message "Successfully verified GitHub CLI". You can now interact with the GitHub platform through the command line terminal. The next step is to implement automatic completion, which is optional. Just add this line to your ~/.bash_profile:

<code>scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh</code>

You can also run the above commands in the current terminal to get the autocomplete function without restarting the terminal. To confirm that it is valid, type gh repo and press tab twice. It should show four different commands that you can attach to the current repo command.

GitHub CLI Command Structure

gh The command structure is similar to a tree and is easy to remember. Basically there are only two layers of command. The first layer contains only six commands:

  • config
  • repo
  • issue
  • pr
  • gist
  • credits

Each command has a second layer command where you can specify the actions to perform, such as gh repo view or gh pr list. However, the credits command does not have a second-level command. When executed, it will only list the names of the repository contributors. Here is a quick example you can try on your own:

<code>brew install gh</code>

We will introduce the remaining commands in more detail in the following sections.

GitHub repository command

Clone the repository using the gh command is easier than using the git command. To clone, just execute the command in the following format:

<code>sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb</code>

This format makes cloning from memory easier. You no longer need to type or copy paste long Git URLs to clone. Here is an example:

<code>sudo yum localinstall gh_*_linux_amd64.rpm</code>

You can also easily fork an existing repository from the command line to your account. Try this:

<code>yay -S github-cli</code>

During the fork process, the tool will ask if you want to clone it too. If you say "yes", it will perform a clone, set up the remote upstream branch and perform updates automatically for you. This is very convenient. You can confirm this by checking the repository configuration on the command line: git config -e. Here is my output:

eval "$(gh completion -s bash)"

For this project, trunk is the default branch. You need to use the git command to sync your fork repository as usual. For cli Warehouse:

$ gh credits cli/cli

You can also use the gh repo view command to view the description and readme files of the project hosted on GitHub. Try this command:

gh repo clone OWNER/REPO

So far, you have learned how to clone, fork, and view using the gh repo command. Let's create a new GitHub repository from the command line. First, we need to create a new project. Let's quickly generate a Next.js project. When asked, use the "Default Beginner Application" template:

$ gh repo clone tailwindcss/tailwindcss

You will find that the project's local Git repository has been initialized. To create a repository from the command line, just run the following command:

<code>scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh</code>

If you do not specify the --public option, a private repository is created by default. Here is a complete list of flags you can specify:

<code>brew install gh</code>

If you want to create a repository under a different organization, you need to use the following syntax to create a repository: gh repo create org/repo.

(The rest of the article, regarding the Pull Request, Issue, Gist commands, summary and FAQ, due to space limitations, please ask questions in paragraphs, and I will answer them in detail one by one.)

The above is the detailed content of GitHub CLI: A Guide to GitHub from the Command Line. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Top 21 Developer Newsletters to Subscribe To in 2025Top 21 Developer Newsletters to Subscribe To in 2025Apr 24, 2025 am 08:28 AM

Stay informed about the latest tech trends with these top developer newsletters! This curated list offers something for everyone, from AI enthusiasts to seasoned backend and frontend developers. Choose your favorites and save time searching for rel

Serverless Image Processing Pipeline with AWS ECS and LambdaServerless Image Processing Pipeline with AWS ECS and LambdaApr 18, 2025 am 08:28 AM

This tutorial guides you through building a serverless image processing pipeline using AWS services. We'll create a Next.js frontend deployed on an ECS Fargate cluster, interacting with an API Gateway, Lambda functions, S3 buckets, and DynamoDB. Th

CNCF Arm64 Pilot: Impact and InsightsCNCF Arm64 Pilot: Impact and InsightsApr 15, 2025 am 08:27 AM

This pilot program, a collaboration between the CNCF (Cloud Native Computing Foundation), Ampere Computing, Equinix Metal, and Actuated, streamlines arm64 CI/CD for CNCF GitHub projects. The initiative addresses security concerns and performance lim

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor