Git checkout/pull doesn't remove directories?
Git doesn't track directories, so it won't remove ones that become empty as a result of a merge or other change. However, you can use git clean -fd
to remove untracked directories (the -fd
flag means force removal of untracked files and directories).
As part of most operations that alter the working tree (pull, merge, checkout, etc.) git will remove any directories which are made empty by that operation (i.e. git removed the last file).
git won't remove any directories that aren't completely empty, so if you have hidden or ignored files then just because git removes the last tracked file from that directory doesn't necessarily mean that git will be able to remove that directory. git doesn't consider this to be an error condition so won't complain about it.
I had same issue, in my case on build service (CI).. as GIT pulls all files without cleaning folders, all the bin / obj that were previously builded by the CI are dirty, so If I remove a test project, the bin will still contain the DLL and will mention tests that does not exist.
In order to solve this issue; this command seems to do the trick (at least for me)
git clean -fd -x
where X will remove all untracked files:
-X Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.