Skip to content

/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.

bash
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

CommandResult
git commit -am "message"Saves the edits as a commit, which the rebase then replays.
git stash then git stash popSets the edits aside and restores them after the pull.
git pull --rebase --autostashDoes 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