Removing a git submodule

October 31, 2013

Git submodules are super handy and awesome. But quickly become a pain if you dont have them setup right. This link by David Walsh covers how to remove a git submodule on his site, but I’ll put it here to look it up quickly.

Delete the relevant section from the .gitmodules file. The section would look similar to:

    [submodule "vendor"]
    path = vendor
    url = git://github.com/some-user/some-repo.git

Stage the .gitmodules changes via command line using:

1
git add .gitmodules

Delete the relevant section from .git/config, which will look like:

    [submodule "vendor"]
    url = git://github.com/some-user/some-repo.git

Run

1
git rm --cached path/to/submodule
. Don’t include a trailing slash – that will lead to an error.

Run

1
rm -rf .git/modules/submodule_name

Commit the changes

Delete the now untracked submodule files

1
rm -rf path/to/submodule

A long time between drinks

so what the heck you been doing? Continue reading