Skip to content

Instantly share code, notes, and snippets.

@lotosbin
Forked from markhepburn/mv-submodule.sh
Created December 20, 2012 15:58
Show Gist options
  • Select an option

  • Save lotosbin/4346161 to your computer and use it in GitHub Desktop.

Select an option

Save lotosbin/4346161 to your computer and use it in GitHub Desktop.
#!/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