Skip to content

Dirty Index During Rebase

Error message

                error: cannot rebase: You have unstaged changes.
              

Quick summary

Git refuses to start a rebase because you have uncommitted changes that would be lost.

Why this happens

  • You have modified files that are not committed or stashed

  • You have staged changes that are not committed

  • You tried to rebase with a dirty working tree

Minimal example

✗ Broken code
git rebase main  # error: cannot rebase: You have unstaged changes.
✓ Fixed code
git stash
git rebase main
git stash pop

Stash your uncommitted changes, perform the rebase, then pop the stash to restore them.

How to diagnose

  • Run git status to see uncommitted changes

  • Decide if changes should be committed, stashed, or discarded

How to fix

  • Stash changes: git stash, then rebase, then git stash pop

  • Commit changes: git add . && git commit -m "Save before rebase"

  • Discard changes: git reset --hard (destructive — only if you do not need them)

How to prevent

  • Commit or stash before rebasing

  • Run git status before starting a rebase

Related Resources

Related Glossary

Related Lessons

← Back to language