GitHub CLI

📟

GitHub in your terminal.

GitHub CLI brings GitHub to your terminal with the gh command. It reduces context switching between browser and terminal. It is available for macOS, Windows, and Linux for free.

# Install it with brew on macOS
$ brew install gh
bash

# Difference to Git

git is the version control system. You use it to track changes, commit code, and sync with a remote repository - see git intro. gh is the GitHub CLI. You use it to interact with GitHub features that are not part of Git itself, like Pull Requests, Issues, and Releases. Think of it this way:

  • git: commit, push, pull, merge, checkout
  • gh: pr create, issue list, release create, repo view

# Create a repo and connect it to GitHub

Here is an example on how to use git to create a local repo and gh to create and connect a remote repo at GitHub. This will also push the content right away.

# Initialize a new git repository
git init

# Add files and commit
git add .
git commit -m "Init"

# Create a new public repository on GitHub from the current directory
gh repo create --public --source=. --push
# Follow the steps

# Once this is done, just push like this
git push
bash

# More examples

# Create a pull request from your current branch
$ gh pr create
 
# Checkout a pull request locally
$ gh pr checkout 123

# List open issues assigned to you
$ gh issue list --assignee "@me"

# View a specific issue in the browser
$ gh issue view 123 --web

# Clone a repository
$ gh repo clone fortrabbit/docs

# Open the current repository in your browser
$ gh browse
bash

Found a tpyo?Edit