While the standard git command-line interface provides comprehensive version control operations for local commits, branches, and remotes, collaborating on GitHub typically forces developers out of the terminal and into a web browser. Opening browser tabs to create pull requests, review peer code diffs, check CI/CD GitHub Actions build logs, or triage issue tickets disrupts developer focus. The official GitHub CLI (gh) brings the entire GitHub collaborative platform directly into your command line, enabling seamless repository and workflow management without switching context.
Key Capabilities of GitHub CLI (gh)
Unlike third-party wrapper scripts, gh is maintained directly by GitHub and integrates natively with modern terminal environments:
- Pull Request Management: Create, checkout, review, comment, and merge pull requests directly from your terminal prompt.
- Issue Tracking: File, assign, list, and close issue tickets using interactive terminal prompts or markdown templates.
- GitHub Actions Monitoring: View real-time CI/CD workflow runs, inspect failed job logs, and trigger manual dispatch events.
- Repository & Release Administration: Fork repositories, clone projects using short aliases, and publish tagged release assets.
Step 1: Install GitHub CLI on Linux
Install the official gh package using your distribution’s package manager:
On Ubuntu and Debian
# Add official GitHub CLI repository and signing key
sudo mkdir -p -m 755 /etc/apt/keyrings
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y
On Fedora, CentOS, and RHEL
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh -y
On Arch Linux and Manjaro
sudo pacman -S github-cli
Verify the Installation
gh --version
Step 2: Authenticate with Your GitHub Account
Before issuing repository commands, authenticate your terminal session with GitHub:
gh auth login
The interactive setup wizard prompts you to configure your authentication preferences:
- Select GitHub.com (or your enterprise server).
- Select your preferred Git protocol: SSH or HTTPS.
- Choose to authenticate via Web browser or paste a Personal Access Token (PAT).
- If you choose browser authentication,
ghdisplays an 8-character verification code and opens your browser. Confirm the code to complete secure authorization.
Verify that your session is actively authenticated:
gh auth status
Step 3: Clone, Fork, and Create Repositories
Streamline your repository onboarding workflows:
Clone a Repository Using Short Names
You no longer need to copy long HTTPS or SSH URLs from browser tabs:
# Clone owner/repo directly
gh repo clone torvalds/linux
# Clone into a specific folder
gh repo clone my-org/web-service my-app
Fork a Project and Configure Upstream Automatically
When contributing to open-source software, gh repo fork creates a fork in your personal account, clones the codebase locally, and configures both origin and upstream remotes automatically:
gh repo fork cli/cli --clone
Step 4: Create and Review Pull Requests
Manage the entire code review cycle without leaving your shell:
Create a Pull Request
Once you commit your changes to a feature branch and push to your remote, generate a pull request interactively:
# Interactive wizard prompting for title and body
gh pr create
# Or supply title and body inline
gh pr create --title "feat: implement rate limiting middleware" --body "Resolves issue #42" --draft
Checkout and Test a Teammate’s Pull Request Locally
To inspect and run a colleague’s PR branch locally without manually fetching remotes:
gh pr checkout 104
Git automatically pulls the branch, checks it out, and sets up local branch tracking.
Merge a Pull Request
# Squash and merge, then delete the remote branch
gh pr merge 104 --squash --delete-branch
Step 5: Triage Issues and Monitor GitHub Actions
Track project bugs and CI/CD automation directly from your workspace:
List and Filter Issues
# List open issues assigned to you
gh issue list --assignee "@me"
# View issue details inside the terminal
gh issue view 85
Monitor GitHub Actions CI/CD Workflows
# View recent workflow runs and their pass/fail statuses
gh run list
# Stream live build logs for the latest workflow
gh run watch
# Re-run a failed workflow job
gh run rerun 12345678 --failed
Productivity Tip: Configure Shell Aliases
Accelerate your daily Git cadence by configuring persistent shortcuts using gh alias:
# Create an alias to check out your open PRs quickly
gh alias set myprs 'pr list --author "@me"'
# Usage
gh myprs