Command Palette

Search for a command to run...

GitHub CLI Installation Guide

A comprehensive guide for installing and configuring GitHub CLI (gh) on different operating systems

GitHub CLI (gh) is GitHub's official command-line tool that brings GitHub to your terminal. It reduces the need to switch between the browser and terminal by enabling you to manage GitHub workflows directly from the command line.

Prerequisites

  • A system running Windows, macOS, or Linux
  • Administrative/sudo privileges
  • Terminal/Command Prompt access
  • Internet connection for downloading packages
  • A GitHub account

Installation Instructions

Ubuntu/Debian Installation

# Add GitHub CLI repository
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
 
# Update package list and install
sudo apt update
sudo apt install gh -y

Post-Installation Configuration

After installing GitHub CLI, authenticate with your GitHub account:

# Start the login process
gh auth login
 
# Follow the interactive prompts to:
# 1. Select GitHub.com or GitHub Enterprise Server
# 2. Choose your preferred protocol (HTTPS or SSH)
# 3. Authenticate through your browser or with a token

Verification

Verify the installation by checking the GitHub CLI version:

gh --version

Common Commands and Usage

Repository Operations

# Clone a repository
gh repo clone owner/repo
 
# Create a new repository
gh repo create [name] [flags]
 
# Fork a repository
gh repo fork [repository]
 
# View repository
gh repo view [repository]

Issue Management

# Create an issue
gh issue create
 
# List issues
gh issue list
 
# View an issue
gh issue view [issue-number]
 
# Close an issue
gh issue close [issue-number]

Pull Request Operations

# Create a pull request
gh pr create
 
# List pull requests
gh pr list
 
# Check out a pull request locally
gh pr checkout [pr-number]
 
# View a pull request
gh pr view [pr-number]

Troubleshooting

Common Issues

  1. Authentication Failed

    • Ensure you have a valid GitHub account
    • Check your internet connection
    • Try regenerating your authentication token
    • Verify you have the correct permissions
  2. Command Not Found

    • Ensure GitHub CLI is properly installed
    • Check if the installation directory is in your PATH
    • Try closing and reopening your terminal
  3. API Rate Limiting

    • Authenticate with your GitHub account
    • Wait for rate limit to reset
    • Use authenticated requests

Security Considerations

  1. Keep GitHub CLI updated to the latest version
  2. Use token-based authentication instead of password
  3. Enable two-factor authentication on your GitHub account
  4. Regularly rotate access tokens
  5. Be cautious when using scripts that automate GitHub CLI commands

Environment Variables

GitHub CLI respects several environment variables:

# Set default GitHub host
export GH_HOST="github.com"
 
# Set default editor
export GH_EDITOR="vim"
 
# Set default browser
export GH_BROWSER="firefox"

Additional Resources