Read Anthropic’s case study about Graphite Reviewer

Resolving git rebase conflicts

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


Rebasing in Git is a technique that can help streamline your commit history, making it easier to understand and manage. However, when performing a rebase, you may sometimes encounter conflicts. Rebase conflicts happen when Git is unable to automatically reconcile changes from different branches. This guide will walk you through the steps to handle conflicts during a Git rebase.

A rebase conflict arises when Git attempts to reapply commits on top of another branch's base and encounters discrepancies that it cannot resolve on its own. This typically occurs when changes in the branch you’re rebasing are in conflict with changes in the target branch.

  1. Start the rebase: Initiate the rebase process using the following command:

    Terminal
    git rebase <base-branch>

    Replace <base-branch> with the name of the branch you are rebasing onto.

  2. Identify conflicts: During the rebase, if there are conflicts, Git will pause the rebase and list the files that need your attention.

    For example, you may see output like this:

    Terminal
    Auto-merging file.txt
    CONFLICT (content): Merge conflict in file.txt
    Error: could not apply fa39187... your commit message here
    Resolve all conflicts manually, mark them as resolved with
    'git add/rm <conflicted_files>', then run 'git rebase --continue'.
    You can abort the rebase with 'git rebase --abort'.
  3. Resolve the conflicts: Open each conflicted file and make the necessary changes. Conflicts are marked in the file like this:

    Terminal
    <<<<<<< HEAD
    Current branch version of file.txt
    =======
    Incoming changes version of file.txt
    >>>>>>> fa39187... your commit message here

    Edit the file to fix the conflicting sections. You can choose to keep the changes from your branch, the incoming changes, or merge them in any way you see fit.

  4. Mark conflicts as resolved: After resolving each conflict in a file, use the following command to mark it as resolved:

    Terminal
    git add <file-name>

    Alternatively, if a file should be deleted, run:

    Terminal
    git rm <file-name>
  5. Continue the rebase: Once all conflicts have been resolved and marked accordingly, continue the rebase:

    Terminal
    git rebase --continue

    If at any point you wish to stop the rebase and return to the original state, you can do so with:

    Terminal
    git rebase --abort

    This resets your working directory to the state it was in directly before you executed the rebase command.

  6. Complete the rebase: If there are no more conflicts and all changes have been applied, the rebase will finish, and your branch will be updated.

  • List conflicts: To view the list of all conflicts during a rebase, you can run:

    Terminal
    git status
  • Interactive rebase: For more control during a rebase, especially when working with multiple commits, you can use:

    Terminal
    git rebase -i <base-branch>

    This opens up a text editor allowing you to pick, squash, edit, or drop commits.

For a more detailed walkthrough on conflicts and interactive rebasing, see this guide on resolving merge conflicts.

0 min read
0
Share
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