GitHub CLI

Published

Updated

📟

GitHub in your terminal.

GitHub CLI is the free command line tool for GitHub. The gh command creates repositories, pull requests and releases from the terminal.

GitHub CLI runs on macOS, Windows and Linux and is open source under the MIT license.

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

Difference to Git

git tracks changes and syncs them with any remote repository. gh talks to GitHub itself: pull requests, issues, releases and repository settings.

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

Create a repo and connect it to GitHub

Create the repository locally with git, then let gh create the GitHub repository and push to it in one step. Connect that repository to an environment with the GitHub app.

# Initialize a new git repository
git init

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

# Create a private GitHub repository from the current folder and push
gh repo create --private --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

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗