There are useful answers how to remove submodules "locally" - How do I remove a submodule?
However I have the issue I have clones of my repo on several machines. Two I only work once or twice a month. So when I update the branches on those although the submodules are no longer tracked the files are still on the working branch as well in .git/modules
. On more than one occasion I accidentally checked some in. In other cases I have builds failing due to the presence of these unwanted files/directories.
I suppose I could keep a list of stuff to delete - but that doesn't seem right - how about another person would do the removal and I don't have info outside git what to remove?
So what is the suggested way to clean up clones?
update
For me git --version
returns git version 2.18.0
which seems to be current (it is 2018-09-01).
I add a reproducible example.
Setup
mkdir parent
cd parent
git init
git submodule add https://github.com/jakesgordon/javascript-tetris.git
git commit -am add
cd ..
git clone parent clone
cd clone
git submodule update --init
Now both directories contain the submodule with checked out files in javascript-tetris/
. .gitmodules
contains the submodule.
When I do
cd parent
git rm javascript-tetris
git commit -am delete
In parent the directory is javascript-tetris
gone and the entry in .gitmodules
removed. But there remains a populated .git/modules/javascript-tetris
directory.
on the clone side:
git pull
gives the warning: warning: unable to rmdir 'javascript-tetris': Directory not empty
. And the directory remains, also .git/modules/javascript-tetris
is still there.
The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.
A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.
To recap, git clean is a convenience method for deleting untracked files in a repo's working directory. Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .
Is this helpful to you?
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
UPDATE
To remove a submodule you need to:
Delete the now untracked submodule files rm -rf path_to_submodule
Source
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