GitHub CLI for Power Users

Interact with GitHub directly from your terminal.


The GitHub Command Line Interface (CLI), known simply as gh, brings the power and flexibility of GitHub right into your terminal. For developers who live in their shells, this tool can streamline workflows, automate repetitive tasks, and minimize context switching. If you consider yourself a power user, mastering the GitHub CLI will amplify your productivity and deepen your integration with the GitHub platform. In this article, we'll explore advanced usage, customization, and best practices for getting the most out of gh.

Table of Contents


Getting Started with GitHub CLI

If you haven’t installed gh yet, it's available for macOS, Windows, and Linux.

# macOS (Homebrew)
brew install gh

# Ubuntu
sudo apt install gh

# Windows (scoop)
scoop install gh

Verify your installation:

gh --version

Authentication and Configuration

Before you can interact with your repositories, authenticate with GitHub:

gh auth login

Follow the prompts to select GitHub.com or GitHub Enterprise, preferred protocol (HTTPS/SSH), and authentication method. Configure your default editor, pager, and other preferences with:

gh config set editor "vim"
gh config set prompt disabled

List your current configuration with:

gh config list

Command Overview

The GitHub CLI covers a wide range of features:

  • Repositories: gh repo clone, gh repo view, gh repo create
  • Issues: gh issue list, gh issue create, gh issue close
  • Pull Requests: gh pr list, gh pr create, gh pr checkout, gh pr merge
  • Gists: gh gist create, gh gist list
  • Actions: gh run list, gh run watch
  • Releases: gh release list, gh release upload

Each command has subcommands and plenty of flags. Use --help for details.

Power User Workflows

Efficient Issue Management

No more clicking around the web UI.

  • List issues assigned to you:

    gh issue list --assignee "@me"
    
  • Create a new issue with labels and assignee:

    gh issue create --title "Optimize loading times" --body "Profile loading spinner gets stuck" --label "performance,bug" --assignee "@me"
    
  • Close Issues:

    gh issue close 123
    
  • View issue details in your browser:

    gh issue view 123 --web
    

Pull Request Automation

Easily open, checkout, and update PRs.

  • Open a PR for your current branch:

    gh pr create --title "Feature: user login flow" --body "Implements login via OAuth2" --base main
    
  • List open PRs created by you:

    gh pr list --author "@me" --state open
    
  • Checkout a PR:

    gh pr checkout 45
    
  • Comment on a PR:

    gh pr comment 45 --body "Looks great, but needs tests."
    

Review and Merge from the Terminal

Approving and merging PRs is seamless:

  • Approve a PR:

    gh pr review 45 --approve
    
  • Merge with a squash commit:

    gh pr merge 45 --squash --delete-branch
    
  • Merge all ready PRs by label:

    gh pr list --label "ready" --json number | jq '.[].number' | xargs -I{} gh pr merge {} --squash --delete-branch
    

Custom Scripts and Aliases

Power users automate. Speed up repetitive workflows using aliases:

  • Add an alias for checking out PRs by number:

    gh alias set pco 'pr checkout'
    # Usage: gh pco 45
    
  • Alias to list stale issues:

    gh alias set stale 'issue list --state open --sort created --limit 20'
    
  • Integrate with shell scripts:

    Create a script to assign all open bugs to yourself:

    gh issue list --label bug --state open --json number | jq '.[].number' | xargs -I{} gh issue edit {} --assignee @me
    

Pretty Output: Formatting, jq, and Fzf

The --json flag outputs structured data. Use it with jq and fzf for beautiful, interactive command lines.

  • List PR titles interactively:

    gh pr list --json title,number | jq -r '.[] | "\(.number): \(.title)"' | fzf
    
  • Extract and email authors of open PRs:

    gh pr list --json author,email --jq '.[] | "\(.author.login): \(.author.email)"'
    
  • Custom CSV Output:

    gh issue list --json number,title --jq '.[] | [.number, .title] | @csv'
    

Remote Repository Management

Clone, fork, and create repositories without leaving your terminal:

# Clone a repository
gh repo clone octocat/Hello-World

# Fork a repository and clone it
gh repo fork kubernetes/kubernetes --clone

Create new repositories interactively or with flags:

gh repo create my-awesome-project --public --source=. --push

Extensions: Supercharge gh

The CLI supports third-party extensions to add even more power:

  • Browse available extensions:

    gh extension list
    
  • Install an extension:

    gh extension install dlvhdr/gh-dash
    gh dash
    

Some popular extensions:

Tips, Tricks, and Best Practices

  • Tab completion: Enable with gh completion -s bash | source (supports Zsh and Fish).

  • Batch actions: Combine --json output and xargs for mass actions.

  • Interactive mode: Many commands offer interactive prompts when run without arguments.

  • Stay Updated: Upgrade regularly for new features:

    gh version upgrade
    
  • Use --web: Open any item in your browser when terminal UI falls short.

Conclusion

For power users, the GitHub CLI unlocks a streamlined and efficient interaction model with GitHub, from managing issues and reviewing pull requests to scripting and automation. By blending command-line savvy with the newest gh capabilities, you can significantly accelerate your GitHub workflow, freeing up more time to focus on code.

Whether you're an open-source maintainer, enterprise developer, or automation enthusiast, mastering these features will make you faster, smarter, and happier. Embrace the terminal—your GitHub superpowers await!