The following untracked working tree files would be overwritten by checkout:
Nothing drives me crazier than trying checkout a git branch and getting this error.
$ git checkout develop error: The following untracked working tree files would be overwritten by checkout: tests/fixtures/5e1c60f7048c2630c76c7e268ed7ad55 Please move or remove them before you can switch branches. Aborting
This usually happens to me when something in my application creates cache files and the git ignore wasn’t configured. So there are several different ways to solve this depending on what you want to do.
If you want to keep the files just commit them like the warning prompts you to. In this case:
git add tests/fixtures/ git commit -m "Adding fixture files" tests/fixtures/
But sometimes you don’t want to keep them so you delete the file with:
rm -rf tests/fixtures/5e1c60f7048c2630c76c7e268ed7ad55
But then you just get the same error for another file in the same directory. You can’t delete the whole directory because there are some files in it that ARE committed and need to be kept.
What I learned today is that you can use git’s ‘clean’ function to remove these.
git clean -f tests/fixtures/
-f flag here will force delete all of the untracked files in that directory. Alternatively if you want to be more careful you can use
-i for an interactive prompt:
$ git clean -i tests/ Would remove the following items: tests/test-input-helper.php tests/test-site-workflow.php *** Commands *** 1: clean 2: filter by pattern 3: select by numbers 4: ask each 5: quit 6: help What now> 5 Bye.