Gitextensions: Checkout branch not clearing Submodule folders

Created on 29 Sep 2015  ·  4Comments  ·  Source: gitextensions/gitextensions

I have the below (simplified) branch structure

/Master
readme.md

/develop
readme.md
folder1/
sub-module initialized into this folder

I would expect that when I switch between the 2 branches the submodule folder is removed aswell. I am on Windows 10 using version 2.48.05

The actual message I am getting is

"C:\Program Files (x86)\Git\bin\git.exe" checkout "master"
Your branch is up-to-date with 'origin/master'.
warning: unable to rmdir Daedalus.Web/Areas/blog: Directory not empty
warning: unable to rmdir Daedalus.Web/Areas/emails: Directory not empty
Switched to branch 'master'
Done

Could anyone shed any light on why this could be happening or how I can get around it. My project is private but if need be I will try and recreate the issue on a public Git to demo the issue

git issue

Most helpful comment

For anyone looking for a solution: (sorry I'm 4 years late...)

Newer Git versions (Git >= 2.13) simplify all this by adding the --recurse-submodules flag to the git checkout command, which takes care of placing the submodules in the right state for the branch we are switching to.

Use git checkout --recurse-submodules master

Use git config submodule.recurse true to tell git to always use --recurse-submodules (only in git versions 2.14+)

Source is from @Radrik5's post above

All 4 comments

Could you try running git checkout master in Git Bash?
What are the files in blog and email folders? Are they in .gitignore?

Hi @Radrik5,

I have just tried this in Git Bash and I get the same message as above. Directories now empty etc

You mentioned the .gitignore - should the sub-modules folder be named in the Main repos .gitignore?

In the sub-modules folders there are some folders, .html, .cs files etc

It seems that this is a well-known issue with submodules. See https://git-scm.com/book/en/v2/Git-Tools-Submodules#Issues-with-Submodules.

For anyone looking for a solution: (sorry I'm 4 years late...)

Newer Git versions (Git >= 2.13) simplify all this by adding the --recurse-submodules flag to the git checkout command, which takes care of placing the submodules in the right state for the branch we are switching to.

Use git checkout --recurse-submodules master

Use git config submodule.recurse true to tell git to always use --recurse-submodules (only in git versions 2.14+)

Source is from @Radrik5's post above

Was this page helpful?
0 / 5 - 0 ratings