Reflect on your 2024 year in code

gh

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


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.

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.

  • 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.

After installation, you can run gh commands from your terminal. Here are a few common examples:

Terminal
gh auth login

Follow the prompts to connect your GitHub account.

Terminal
# from a branch with new changes
gh pr create --fill
  • --fill uses your current commits and branch name to fill in the pull request details automatically.
Terminal
gh pr list
Terminal
gh issue list
gh issue view <issue_number>

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).

  • 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.

You can install the Graphite CLI (gt) via Homebrew or npm. It’s fully compatible with existing repositories—just install and start using it.

Terminal
brew install withgraphite/tap/graphite
gt --version
  • MacOS: The recommended method is via Homebrew.
  • Linux: Homebrew on Linux is also supported.
Terminal
npm install -g @withgraphite/graphite-cli@stable
gt --version

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.

  1. Sign Into the Graphite Web App Visit https://app.graphite.dev/activate and log in with your GitHub account.

  2. Copy your auth command You’ll see a command of the form:

    Terminal
    gt auth --token <YOUR_AUTH_TOKEN>

    This token will be unique to your user account.

  3. 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:

Terminal
gt submit

to create or update GitHub pull requests for every branch in your stack.

Below are some common gt commands you’ll use when managing stacked pull requests:

  1. Creating a new stack branch

    Terminal
    gt branch create <branch_name>

    This command sets up a new branch in your stack.

  2. Submitting a pull request

    Terminal
    gt submit

    This will create or update pull requests for each branch that isn’t already merged.

  3. Syncing & updating

    Terminal
    gt up

    Merges the latest changes from parent branches so your stack remains in sync.

  4. Viewing Your Stack

    Terminal
    gt stack

    Displays a graphical tree of your stacked branches.

    screenshot of a stack

  • 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.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone