Read Anthropic’s case study about Graphite Reviewer

Command-line options for merging pull requests

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

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


Merging pull requests is an essential part of the workflow for any team using Git. While many teams use GUI tools or web-based interfaces like GitHub or GitLab to manage pull requests, knowing how to handle these tasks from the command line can save time and streamline workflows. This guide covers various command-line options to merge pull requests, including using standard Git commands and Graphite's advanced CLI tool.

Before diving into merging pull requests from the command line, it's important to understand the basics of the git merge command. The git merge command integrates changes from one Git branch into another. Typically, you'll merge a feature branch into the main branch after completing the development and review process.

To merge a feature branch named feature-login into the main branch:

Terminal
git checkout main
git merge feature-login

This command switches the working directory to the main branch and then merges the changes from feature-login into it.

To merge pull requests via the command line, you typically need to first fetch the changes from the remote repository and then merge them locally. Here’s a detailed approach using Git commands:

  1. Fetch the remote branch: Ensure your local repository is up to date with the remote changes.

    Terminal
    git fetch origin
  2. Check out the branch you want to merge into (usually main):

    Terminal
    git checkout main
  3. Merge the feature branch into the main branch: Replace feature-branch-name with the name of the branch you're merging.

    Terminal
    git merge origin/feature-branch-name
  4. Push the merge to the remote repository:

    Terminal
    git push origin main

This sequence of commands updates your local main branch with the changes from the feature-branch-name.

Graphite offers a sophisticated CLI tool that simplifies the process of managing pull requests, including merging. The Graphite CLI provides powerful features to automate and optimize how you handle pull requests.

To merge a pull request using Graphite’s CLI, you can use the following steps:

Terminal
gt pr checkout <pull_request_number>
gt branch merge

The gt pr checkout command checks out the pull request locally, allowing you to review or test the changes before merging. The gt branch merge command then merges the checked-out pull request into your current branch, streamlining the process.

Graphite's CLI also supports stacking multiple pull requests at once, which can be highly beneficial in a busy development environment where dependencies between pull requests are common.

Whether you're using standard Git commands or Graphite's enhanced CLI, the ability to manage and merge pull requests from the command line is a valuable skill. It offers more control and flexibility over your workflow, making it easier to handle complex scenarios that might arise during development.

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