Skip to content

Instantly share code, notes, and snippets.

@andsens
Last active September 18, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andsens/93ec745e1184dae56d1e to your computer and use it in GitHub Desktop.
Save andsens/93ec745e1184dae56d1e to your computer and use it in GitHub Desktop.
Deinitialize a submodule and merge it as a branch
#!/bin/bash -xe
deinit() {
module_path=$1
test -d $module_path
current_branch=$(git rev-parse --abbrev-ref HEAD)
url=$(cd $module_path; git config --get remote.origin.url)
remote_name=$(basename $url)
branch_name=$(basename $url)
head=$(cd $module_path; git rev-parse HEAD)
git remote add -f $remote_name $url
git checkout -fb $branch_name $head
rm -rf $module_path
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&'$module_path'/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"'
git checkout $current_branch
git submodule deinit $module_path
git rm -rf $module_path
git commit -m "Remove $module_path as a submodule"
git merge $branch_name
git branch -d $branch_name
}
deinit $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment