git clean is not removing a submodule added to a branch when switching branches

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

git clean is not removing a submodule added to a branch when switching branches

From: Adrian Cornish <hidden>
Date: 2016-06-15 22:53:06

If I add a submodule to a branch and then switch branches, git
checkout warns it cannot
remove the submodule. If I then issue a git clean - it says it removes
the submodule but
in fact does nothing at all. Is this a bug or expected behaviour.

TIA

Adrian

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)

Re: git clean is not removing a submodule added to a branch when switching branches

From: Jens Lehmann <hidden>
Date: 2016-06-15 22:53:06

Am 18.02.2012 22:27, schrieb Adrian Cornish:
If I add a submodule to a branch and then switch branches, git
checkout warns it cannot
remove the submodule. If I then issue a git clean - it says it removes
the submodule but
in fact does nothing at all. Is this a bug or expected behaviour.
Right this is just how things work. I won't call it expected behavior,
as some users (like you) would expect to see the submodule be removed
(while others are used to the current behavior that submodule work
trees are never touched).

But one of last years GSoC projects took first steps into the
direction of safely removing submodules (without losing any history).
I have experimental code at my Github repo [1] to update submodule
work trees along with the superproject, but polishing that for
inclusion into mainline will still take some time.

[1] https://github.com/jlehmann/git-submod-enhancements
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help