GitHub CLI, or gh, is a powerful tool that brings the full functionality of GitHub to your command line. Whether you’re managing repositories, creating issues, or reviewing pull requests, gh streamlines your workflow by enabling you to interact with GitHub directly from your terminal. In this guide, we’ll walk through the installation process on Ubuntu and provide a cheat sheet of commonly used commands.

Installation on Ubuntu

Using APT (Advanced Package Tool)

Open your terminal and follow these steps:

Step 1: Add the GitHub CLI repository

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages

Step 2: Update package lists

sudo apt update

Step 3: Install GitHub CLI

sudo apt install gh

Once the installation is complete, you can verify it by checking the version:

gh --version

Congratulations! You’ve successfully installed gh on your Ubuntu system.

GitHub CLI Cheat Sheet

Now that gh is installed, let’s explore some essential commands to help you navigate GitHub efficiently:

Repository Interaction

  • gh repo create <repo_name>: Create a new repository.
  • gh repo clone <repo_url>: Clone a repository to your local machine.
  • gh repo view <repo_name>: View repository details in the browser.
  • gh repo fork <repo_name>: Fork a repository.
  • gh repo list: List repositories in your account or organization.

Issue and Pull Request Management

  • gh issue list: List issues in the current repository.
  • gh issue create: Create a new issue.
  • gh issue view <issue_number>: View details of a specific issue.
  • gh issue status: Show status of issues.
  • gh pr list: List pull requests in the current repository.
  • gh pr create: Create a new pull request.
  • gh pr view <pr_number>: View details of a specific pull request.
  • gh pr checkout <pr_number>: Checkout a pull request locally.
  • gh pr merge <pr_number>: Merge a pull request.
  • gh pr diff <pr_number>: View the diff of a pull request.

Workflow and Actions

  • gh workflow list: List workflows for the current repository.
  • gh run list: List recent workflow runs for the current repository.
  • gh run watch <run_id>: Watch the progress of a workflow run.
  • gh run rerun <run_id>: Re-run a workflow.

Collaboration and Teams

  • gh team list: List teams in the current organization.
  • gh team create <team_name>: Create a new team in the organization.
  • gh team view <team_name>: View details of a specific team.

User and Authentication

  • gh auth login: Authenticate with your GitHub account.
  • gh auth logout: Log out of the authenticated account.
  • gh auth status: Check the authentication status.

Labels, Assignees, and Configuration

  • gh issue label: Manage labels for issues.
  • gh issue assign: Assign users to issues.
  • gh config get: Get configuration values.
  • gh config set: Set configuration values.

Help

Access help documentation:

gh help

This cheat sheet covers some basic commands to get you started, but GitHub CLI offers a wide range of functionalities. Use gh help or gh <command> --help for detailed information on specific commands.

Have fun exploring the world of gh!