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

Kenny DuMez
Kenny DuMez
Graphite software engineer


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.

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