14

"Cannot rewrite branch(es) with a dirty working directory".

I am new to Git - I tried googling for an answer to no avail.

What does this error mean? What should/can I do?

2
  • it is my first git repo and I had committed something not belonging... had to correct it. Commented Jan 8, 2010 at 20:52
  • I'm having the same problem and I'm experienced with git. If I do git filter-branch --subdirectory-filter somedir -- --all I end up with my whole repo processed but if I do git filter-branch --tree-filter rm somefile` -- --all` it quits after processing the first branch with the error mentioned above. Why does filter-branch save the state of --subdirectory-filter but stop if --tree-filter changes the directory? Commented Oct 12, 2011 at 19:24

1 Answer 1

24

A dirty working directory means you have uncommitted changes to your branch. You can either commit them or stash them. To stash just use:

git stash 

And use this to bring your changes back

git stash apply 
Sign up to request clarification or add additional context in comments.

3 Comments

Note that you might actually not have a dirty working directory: there's a bug in git prior to 1.7.7.1 which means git doesn't refresh its internal indexes when running filter-branch. So try running these two commands anyway - unless anyone knows of a less hacky way to force index refresh. (More discussion of this on this question .)
From a comment added at the link above: git update-index -q --ignore-submodules --refresh should update the index!
You can use git stash pop to apply the last stashed changes and remove them from the stash list. apply will apply the changes but a git stash list still shows the stashed changes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.