Read Anthropic’s case study about Graphite Reviewer

Git pull rebase

Greg Foster
Greg Foster
Graphite software engineer


Note

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


git pull --rebase combines the functionality of git fetch with git rebase. This guide provides a detailed understanding of how to use git pull rebase effectively in your development workflow.

When you perform a git pull, Git by default merges the fetched changes with your local branch. This merge can create a merge commit, which might clutter your project history. Using git pull --rebase instead of the default git pull (which by default is git pull --merge) rewrites your local branch's history by reapplying your work on top of what came down from the server.

Using git pull --rebase keeps your project history cleaner and linear, which simplifies both navigation and troubleshooting. By integrating the base branch changes without adding additional merge commits, rebasing avoids cluttering the branch history, making it easier to follow the development process and identify specific changes.

Additionally,in a rebase workflow, reverting changes is more straightforward since each commit is applied one at a time, making it easier to isolate and undo specific changes without disrupting the entire branch history.

To avoid having to specify --rebase every time you pull, you can configure Git to make rebasing the default behavior when you execute a git pull. You can do this globally or just for a specific repository.

  1. Global configuration:

    Terminal
    git config --global pull.rebase true

    This command sets rebasing as the default method for any repository you work with on your machine.

  2. Repository-specific configuration:

    Terminal
    git config pull.rebase true

    This sets rebasing as the default method only within the current repository.

  • git rebase false: This is the default setting where git pull executes a merge.
  • git rebase true: This makes every git pull use the rebase method.
  • git rebase merges: This is a nuanced setting that rebases the changes but preserves merge commits.

To pull and rebase the current branch on top of the upstream branch, you can use:

Terminal
git pull --rebase

If you want to be more specific about the remote and branch you are pulling from, you might use:

Terminal
git pull origin main --rebase

This command fetches the new commits from the main branch of the origin remote and rebases your current branch on top of these fetched changes.

If you're working on a local branch that needs updating with respect to an upstream branch, you can specify the branch as well:

Terminal
git pull origin your-branch-name --rebase

This pulls changes from your-branch-name on the origin remote and rebases your current branch onto it.

During a rebase, conflicts may occur. Here's how you handle them:

  1. Identify the conflict: Git will stop at the first problematic commit and output a message indicating a conflict.
  2. Resolve the conflict: Open the conflicting files and make the necessary changes.
  3. Add the resolved files: Use git add <file-name> to mark conflicts as resolved.
  4. Continue the rebase: Run git rebase --continue to proceed with the rebase.
  5. Abort the rebase (if needed): If you decide not to continue with the rebase, you can revert to the original branch state by running git rebase --abort.

For a more detailed step-by-step walkthrough, see this guide on resolving merge conflicts.

For further detail on rebasing see the official Git documentation.

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