Home > Technology peripherals > It Industry > GitHub CLI: A Guide to GitHub from the Command Line

GitHub CLI: A Guide to GitHub from the Command Line

尊渡假赌尊渡假赌尊渡假赌
Release: 2025-02-14 10:11:11
Original
241 people have browsed it

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>
Copy after login
Copy after login
Copy after login
macOS:
<code>brew install gh</code>
Copy after login
Copy after login
Copy after login
Debian/Ubuntu Linux:
<code>sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb</code>
Copy after login
Copy after login
Fedora/Centos Linux:
<code>sudo yum localinstall gh_*_linux_amd64.rpm</code>
Copy after login
Copy after login
Arch Linux:
<code>yay -S github-cli</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login
Copy after login

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>
Copy after login
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

<code>yay -S github-cli</code>
Copy after login
Copy after login

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)"
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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>
Copy after login
Copy after login
Copy after login

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>
Copy after login
Copy after login
Copy after login

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 of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template