Skip to content

Instantly share code, notes, and snippets.

@markhepburn
Created January 14, 2012 13:26
Show Gist options
  • Save markhepburn/1611414 to your computer and use it in GitHub Desktop.
Save markhepburn/1611414 to your computer and use it in GitHub Desktop.
Shell script to automate moving a git submodule
#!/bin/bash
# See for eg
# http://stackoverflow.com/questions/4526910/rename-a-git-submodule;
# an important point seems to be to avoiding the trailing '/' when
# calling 'add' in the new location.
# Also, note that the name ([submodule = "name"]) in the .gitmodules
# file can be anything; it's just used to map to the corresponding
# .git/config entry.
# basename, to strip the trailing '/' off, which would bollocks things up immensely:
submod=`basename $1`
# check that it's a submodule:
if ! test -d $submod/.git; then
echo "Error: not a submodule; move normally"
exit -1
fi
sed -i "s/path = ${submod}/path = thirdparty\/${submod}/" .gitmodules
git add .gitmodules
mv $submod thirdparty
git add thirdparty/$submod
git rm --cached $submod
git ci -m "Moving submodule ${submod} to the thirdparty directory"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment