git rebase_error ai_generated true

error: cannot rebase: You have unstaged changes. Please commit or stash them.

ID: git/cannot-rebase-unstaged-changes

Also available as: JSON · Markdown
95%Fix Rate
95%Confidence
150Evidence
2015-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

Git refuses to rebase because there are uncommitted changes in the working tree. Rebase rewrites commits and needs a clean working directory to avoid losing changes.

generic

Workarounds

  1. 95% success Stash changes, rebase, then pop the stash
    git stash
    git rebase origin/main
    git stash pop
    # If stash pop has conflicts:
    git stash drop  # after resolving manually

    Sources: https://git-scm.com/docs/git-stash

  2. 92% success Commit the changes as a WIP commit, rebase, then soft reset
    git add -A && git commit -m 'WIP: save before rebase'
    git rebase origin/main
    git reset --soft HEAD~1
    # Your changes are now staged again, rebase is done

    Sources: https://git-scm.com/docs/git-reset

Dead Ends

Common approaches that don't work:

  1. Using git checkout . to discard all changes before rebase 65% fail

    This permanently deletes all uncommitted work. If the changes were important, they are lost forever with no way to recover.

  2. Using git rebase --force or --no-verify to bypass the check 95% fail

    There is no --force flag for git rebase that bypasses the dirty working tree check. --no-verify only skips hooks, not the clean tree requirement.

Error Chain

Leads to:
Frequently confused with: