Wednesday, March 3, 2010

git submodule moving

how do you update a git submodule? say the submodule used to be at gitosis@example.com:submodule_a.git, but the developers switched hosts and now it's at gitosis@example.net:submodule_a.git. turns out all you have to do is change .git/config.

in superproject/.git/config


before:
[submodule "submodule_a"]
url = gitosis@example.com:submodule_a.git

after:
[submodule "submodule_a"]
url = gitosis@example.net:submodule_a.git


now git submodule update will use example.net instead of example.com. but that doesn't change the content of the repository, just the configuration for your local copy of the superproject. if someone clones your repo, they'll try to reach the submodule at gitosis@example.com:submodule_a.git. to avoid this, update .gitmodules to point at the new location as well.

in superproject/.gitmodules


before:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.com:submodule_a.git

after:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.net:submodule_a.git

when git submodule init reads the .gitmodules file (in a newly cloned repo), it will get the new location for the submodule and setup the .git/config file accordingly.

helpful, but not what i wanted


places i went looking for this info, but didn't find it:
http://book.git-scm.com/5_submodules.html
http://progit.org/book/ch6-6.html
http://pitupepito.homelinux.org/?p=24
http://gaarai.com/2009/04/20/git-submodules-adding-using-removing-and-updating/
http://www.hackido.com/2009/01/quick-tip-remove-git-submodule.html

No comments:

Post a Comment

Where am I?