/errors/git/cannot-pull-with-rebase-you-have-unstaged-changes
error: cannot pull with rebase: You have unstaged changes.
verified onenvironmentlocal · linux 6.18.44-fc-v140 x64 · GNU bash 5.2.21 · git version 2.43.0updated
- tool
- Git
- exit code
- 128
- versions
- Git 2.x
- os
- linux, macos, windows
error: cannot pull with rebase: You have unstaged changes. means Git will not start a rebase while tracked files have uncommitted edits. Commit the work, stash it, or let Git stash it for you with git pull --rebase --autostash. Untracked files do not trigger the error.
Reproduce it
A remote with a file, a clone, a new commit on the remote, then an uncommitted edit in the clone.
git init -q -b main up
git -C up config user.email a@example.com
git -C up config user.name A
echo one > up/f
git -C up add f
git -C up commit -q -m base
git clone -q up cl
echo two > up/g
git -C up add g
git -C up commit -q -m more
cd cl
echo edit >> f
git pull --rebase 2>&1 | grep '^error: cannot'
exit ${PIPESTATUS[0]}Output · exit 128
error: cannot pull with rebase: You have unstaged changes.
Fixes
| Command | Result |
|---|---|
git commit -am "message" | Saves the edits as a commit, which the rebase then replays. |
git stash then git stash pop | Sets the edits aside and restores them after the pull. |
git pull --rebase --autostash | Does the stash and the restore in one command. |
To make autostash the default for rebases, run git config --global rebase.autoStash true. If the stash cannot be re-applied cleanly, Git reports a conflict and keeps the stash entry, so nothing is lost.
Sources
Related pages
errors · gitfatal: Not possible to fast-forward, aborting.git pull --ff-only (or pull.ff only) aborts when local and remote branches diverged. Rebase or merge the remote commits, or reset if local ones are not needed.errors · giterror: Your local changes to the following files would be overwritten by checkoutGit refuses to switch branches when uncommitted edits would be lost in files that differ between branches. Commit, stash and pop, or use git switch -m.config · gitgit config pull.rebase: merge or rebase on git pullpull.rebase decides whether git pull merges or rebases diverged branches. When it is unset, Git stops with Need to specify how to reconcile divergent branches.