How do I get rid of submodules when switching branches. I do not understand why git clean says it removed the submodule but does not. Is this a bug? Below are cut&paste steps to reproduce.
git --version git version 1.7.8.4 git init submod cd submod echo "This is a submodule" > README.txt git add . git commit -m "Initial commit" cd .. git init prog cd prog echo "This is a program" > README.txt git add . git commit -a -m "Initial commit" git checkout -b topic1 git submodule add ../submod git commit -m "Added submodule" git checkout master #warning: unable to rmdir submod: Directory not empty #Switched to branch 'master' git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # submod/ #nothing added to commit but untracked files present (use "git add" to track) git clean -fd #Removing submod/ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # submod/ #nothing added to commit but untracked files present (use "git add" to track)
Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .
It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.
You can set the submodule to track a particular branch (requires git 1.8. 2+), which is what we are doing with Komodo, or you can reference a particular repository commit (the later requires updating the main repository whenever you want to pull in new changes from the module – i.e. updating the commit hash reference).
This isn't a bug, it's documented behaviour. From man git-clean
:
If an untracked directory is managed by a different git repository, it is not removed by default.
The submod
directory is a different git
repository; if you want to remove it, Use -f option twice if you really want to remove such a directory
.
git clean -f -f -d submod
does remove submod
. See my steps below (almost identical; different git version
and hard-coded submodule
path because otherwise git
spits the dummy).
$ git --version git version 1.7.5.4 # Note, different git-version.
git init submod cd submod echo "This is a submodule" > README.txt git add . git commit -m "Initial commit" cd .. git init prog cd prog echo "This is a program" > README.txt git add . git commit -a -m "Initial commit"
submod
as a git submodule
in topic1
branch. git checkout -b topic1 git submodule add /Users/simont/sandbox/SOTESTING/Subdir-testing/submod git commit -m "Added submodule"
$ git checkout master warning: unable to rmdir submod: Directory not empty Switched to branch 'master' git status # On branch master # Untracked files: # (use "git add ..." to include in what will be committed) # # submod/ #nothing added to commit but untracked files present (use "git add" to track)
git-clean
, then actually git-clean
. git clean -fd #Removing submod/ git status # On branch master # Untracked files: # (use "git add ..." to include in what will be committed) # # submod/ #nothing added to commit but untracked files present (use "git add" to track) $ # As we can see, we haven't actually removed anything yet. $ ls README.txt submod $ git clean -f -f -d submod Removing submod/ $ ls README.txt $ git status # On branch master nothing to commit (working directory clean)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With