Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodules removing on checkout another branch

I have several branches with features in my Git repo.
Every feature is some foreign repo, plugged in as a submodule.
What should I do to correct switching between branches, with and without submodules?

Example:

$ git init
$ git commit -m "empty" --allow-empty
$ git checkout -b feature
$ git submodule init
$ git submodule add git://feature.git feature
$ git commit -a -m "add feature"
$ git checkout master
warning: unable to rmdir feature: Directory is not empty

And we have a feature in our master branch work directory.
How to prevent this?

like image 422
vp_arth Avatar asked Dec 03 '14 06:12

vp_arth


2 Answers

git submodule deinit .

may do the trick

like image 90
Eric Sun Avatar answered Nov 08 '22 06:11

Eric Sun


It seems the easiest way is manually deleting the submodule directories. The price is you have to git submodule init && git submodule update after every checkout.

To match the directories from .gitmodules:

grep path .gitmodules | sed 's/.*= //'

*From Prelang/gist/git-submodule-names

To remove it:

grep path .gitmodules | sed 's/.*= //' | xargs rm -rf
like image 4
Yufan Lou Avatar answered Nov 08 '22 05:11

Yufan Lou