GitHub CLI
Reviewedbyfl
📟
GitHub in your terminal.
GitHub CLI brings GitHub features to your terminal with the `gh` command, reducing context switching between browser and command line.
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
Difference to Git
git is the version control system you use for tracking changes, committing code, and syncing with a repository, while gh is the GitHub CLI that provides access to GitHub-specific features like Pull Requests, Issues, and Releases without leaving the terminal.
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
To create a new repository, initialize one locally with git, then use GitHub CLI to create the corresponding remote repository on GitHub and automatically push your code, establishing version control and creating a backup in one workflow.
# 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
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