When working with GitHub repositories, you often want quick, command-line-driven ways to create pull requests, manage issues, review changes, and more. The GitHub CLI—commonly referred to as gh
—is an official command-line tool that simplifies interaction with GitHub from your terminal.
In addition to the GitHub CLI, you might also be interested in the Graphite CLI (gt
), a separate command-line tool that helps you create and manage stacked pull requests. This guide covers both tools, including when and why you might want to use them, how to install each one, and how to authenticate them with GitHub.
What is gh
?
gh
is the official GitHub CLI, maintained by GitHub. It provides a convenient way to perform various GitHub-related tasks:
- Creating pull requests (
gh pr create
,gh pr checkout
,gh pr merge
) - Managing issues (
gh issue create
,gh issue status
,gh issue view
) - Working with gists (
gh gist create
,gh gist list
) - Viewing and editing GitHub Actions workflows and runs
- Managing GitHub repositories (viewing, forking, starring)
Essentially, gh
helps reduce context switching between your terminal and the browser. You can remain in your local development environment while still leveraging the full power of GitHub.
Why use gh
?
- Streamlined workflow: Create pull requests without leaving your terminal.
- Automation: Automate repetitive tasks (e.g., labeling issues, merging PRs).
- Scripting: Incorporate GitHub operations into larger scripts and CI/CD pipelines.
Basic usage of gh
After installation, you can run gh
commands from your terminal. Here are a few common examples:
Authenticate with GitHub
gh auth login
Follow the prompts to connect your GitHub account.
Create a pull request
# from a branch with new changesgh pr create --fill
--fill
uses your current commits and branch name to fill in the pull request details automatically.
List pull requests
gh pr list
View issues
gh issue listgh issue view <issue_number>
Introducing the Graphite CLI
While gh
is ideal for general GitHub tasks, the Graphite CLI is purpose-built for breaking up large engineering tasks into a series of small, incremental code changes (i.e., stacked pull requests).
Why use the Graphite CLI?
- Stacked pull requests: Easily manage multiple small PRs that build on each other.
- Improved code reviews: Smaller PRs lead to more targeted, faster reviews.
- Remain unblocked: Quickly update or reorder branches without complex git gymnastics.
- Full Git compatibility: The Graphite CLI integrates seamlessly with existing Git workflows.
Installing the Graphite CLI
You can install the Graphite CLI (gt
) via Homebrew or npm. It’s fully compatible with existing repositories—just install and start using it.
5.1 Homebrew Installation (Recommended)
brew install withgraphite/tap/graphitegt --version
- MacOS: The recommended method is via Homebrew.
- Linux: Homebrew on Linux is also supported.
5.2 npm Installation
npm install -g @withgraphite/graphite-cli@stablegt --version
Authenticating the Graphite CLI
To create or update pull requests on GitHub via the Graphite CLI (gt submit
), you’ll need to authenticate. This involves generating a one-time token and passing it to the CLI.
Sign Into the Graphite Web App Visit https://app.graphite.dev/activate and log in with your GitHub account.
Copy your auth command You’ll see a command of the form:
Terminalgt auth --token <YOUR_AUTH_TOKEN>This token will be unique to your user account.
Paste & run Back in your terminal, paste the
gt auth
command. You should see:Terminal🔐 Saved auth token to "/Users/<username>/.graphite_user_config"This indicates the CLI is now authenticated.
Once authenticated, you can use:
gt submit
to create or update GitHub pull requests for every branch in your stack.
Using the Graphite CLI
Below are some common gt
commands you’ll use when managing stacked pull requests:
Creating a new stack branch
Terminalgt branch create <branch_name>This command sets up a new branch in your stack.
Submitting a pull request
Terminalgt submitThis will create or update pull requests for each branch that isn’t already merged.
Syncing & updating
Terminalgt upMerges the latest changes from parent branches so your stack remains in sync.
Viewing Your Stack
Terminalgt stackDisplays a graphical tree of your stacked branches.
Summary
gh
(GitHub CLI) is a powerful, official tool from GitHub for day-to-day repository management, including PRs, issues, and repository configuration.- The Graphite CLI is an additional layer focusing on stacked pull requests and enabling smaller, more manageable code review workflows.
- Both can coexist in your toolbox, each serving a distinct purpose. Installing both allows you to handle general GitHub tasks via
gh
while leveraging Graphite’s powerful stacked PR features when splitting up large feature branches.
By combining these two tools, you can streamline code reviews, simplify your workflow, and keep your branches organized—leading to quicker, higher-quality code merges.