Git bash giving error of warning: unable to rmdir

Viewed 10331

I am using git bash on windows 10 which was recently updated to creators update.

whenever i am trying to switch between branches i get following thing

$ git fetch && git checkout master
warning: unable to rmdir Ionic_Developemnt: Directory not empty
Checking out files: 100% (6312/6312), done.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

I don't know why this is happening also there is a .git hidden folder in the Ionic_Development folder

Can anyone help with this why so error _/_

4 Answers

Found the answer, instead of git checkout, use git checkout --recurse-submodules.

Use git config submodule.recurse true to tell git always use --recurse-submodules (only in git versions 2.14+), add --local if you want that only in local project level.

Reason: This issue happens on (Git < 2.13) when git checkout could not take care of those submodules correctly.

Reference: https://github.com/gitextensions/gitextensions/issues/2966#issuecomment-622666568


Original Answer

Actually I think this answer is partially right :O

If a folder is tracked by local .git within that folder, it would be changed according to .git when you switch branches (e.g. deleted from our point of view, if the other branch does not have this folder).

If a folder is ignored by .gitignore, the folder would be left unchanged when you switch branches.

However, if the folder is a submodule, which is tracked by submodule .git, local .git would try use rmdir when switching branches, which caused the problem.

I know this is old, but in case anyone stumbles on this, as I did, it can also be that you're switching to a different branch and you have a Git submodule. Look for the .git hidden folder in the directory, you can delete it if you don't need it to be a submodule--just be sure to commit the folder to the parent repo in the current branch before switching.

rm -r .git
Related