Read Anthropic’s case study about Graphite Reviewer

How to resolve the Git error "cannot pull with rebase you have unstaged changes"

Kenny DuMez
Kenny DuMez
Graphite software engineer
Try Graphite


Note

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


When working with Git, you may encounter the error message "Cannot pull with rebase: You have unstaged changes." This error occurs when you try to pull changes from a remote repository using rebase while you have local changes that are neither staged nor committed. This guide will help you understand why this happens and how to resolve the issue.

This Git error prevents you from rebasing (moving or combining a sequence of commits to a new base commit) because local changes could be overwritten during the process. If unstaged changes are present, Git cannot apply the changes from the remote branch without risking loss of local changes.

First, use the git status command to assess which files are modified but not staged:

Terminal
git status

This command will list all the changes in your working directory that are not yet staged for a commit.

To save your local modifications temporarily and revert the working directory to match the HEAD commit, use git stash. This command is useful for preserving changes without committing them:

Terminal
git stash push -m "Your stash message"

This action stashes your changes and cleans your working directory.

Now that your working directory is clean, you can safely pull with rebase:

Terminal
git pull --rebase

This command fetches the changes from the remote repository and rebases your current branch on top of the remote branch.

After the rebase is complete, you can apply the changes you stashed earlier:

Terminal
git stash pop

This action reapplies your previously stashed changes to your working directory. If there are any conflicts, Git will prompt you to resolve them.

If you prefer not to use stashing, you have a couple of other options:

  • Commit the changes: If your changes are complete and ready to be saved, you can commit them before performing the rebase:
    Terminal
    git add .
    git commit -m "Commit message"
    git pull --rebase
  • Discard the changes: If you don't need the local changes, you can discard them:
    Terminal
    git checkout -- .
  • Regular commits: Make regular commits to avoid accumulating many unstaged changes, which can complicate pulling and merging.
  • Frequent pulls: Regularly pull changes from the remote repository to minimize the divergence of your branch from the main branch, reducing the complexity of rebasing.
  • Communication: Coordinate with your team when using rebase in shared branches, as it can rewrite commit history and potentially cause confusion.

If after following the steps above, you are still unable to resolve the "Cannot pull with rebase: You have unstaged changes" error, see the official Git documentation on rebasing.

The Graphite CLI is designed to simplify complex Git workflows while introducing advanced features like PR stacking.

  • Simplified workflows: Commands like gt sync and gt restack bundle multiple Git operations into a single step.
  • PR stacking: Manage complex branch dependencies effortlessly, breaking large changes into smaller, reviewable chunks.
  • Seamless integration: Graphite works with your existing Git and GitHub setup, enhancing rather than replacing your current tools.

Graphite’s CLI is particularly effective for teams managing large-scale projects with multiple contributors, enabling faster iteration and reduced friction in Git workflows.

For more on Graphite CLI’s capabilities, visit the official documentation.

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