How to merge pull requests locally

Sara Verdi
Sara Verdi
Graphite software engineer


Note

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


Merging a pull request locally is a Git workflow that allows you to integrate changes from a remote repository into your local development branch before officially finalizing the merge on GitHub. This guide will walk you through how to merge a pull request locally using both Git commands and Graphite CLI, a tool that enhances your Git workflows.

Here are the steps to merge a pull request locally using Git:

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

    Terminal
    git fetch origin
  2. Check out the branch you want to merge: Switch to the branch that has the pull request.

    Terminal
    git checkout feature-branch
  3. Pull the changes to your local system: Merge the changes from the remote feature branch into your local branch.

    Terminal
    git pull origin feature-branch
  4. Merge the changes into your local main branch: Check out the main branch and merge the feature branch into it.

    Terminal
    git checkout main
    git merge feature-branch
  5. Resolve any conflicts: If there are conflicts, Git will pause the merge and ask you to resolve them. Once resolved, you can continue the merge process.

  6. Test the merged code: Before pushing the merge back to the remote repository, thoroughly test the code to ensure it works as expected.

Graphite CLI simplifies managing complex stacks of changes, including merging pull requests. Here's how to merge a pull request locally using Graphite CLI:

  1. Sync your local repository: Keep your local repository synchronized with the remote.

    Terminal
    gt sync
  2. Check out the branch associated with the PR: Use the Graphite CLI to check out the branch for the pull request.

    Terminal
    gt checkout feature-branch
  3. Merge the PR locally: With the branch checked out, you can merge it into your main branch.

    Terminal
    gt checkout main
    gt merge feature-branch
  4. Resolve conflicts with Graphite’s tools: If there are any conflicts, Graphite CLI provides tools to handle them smoothly.

    Terminal
    gt continue
  5. Test and finalize the merge: Test the changes locally. If everything works as expected, you can push the merged changes back to the remote repository.

    Terminal
    git push origin main

Merging pull requests locally allows developers to test changes in their environment, resolving potential conflicts and issues before the changes affect the main or master branch. By using Graphite CLI, you can integrate changes more efficiently. Whether you prefer traditional Git commands or Graphite’s enhanced functionality, both methods provide robust solutions for managing and integrating pull requests locally.

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

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2