Skip to content

Instantly share code, notes, and snippets.

@hryamzik
Created June 25, 2015 13:58
Show Gist options
  • Save hryamzik/d3b20b71faf2d9a65780 to your computer and use it in GitHub Desktop.
Save hryamzik/d3b20b71faf2d9a65780 to your computer and use it in GitHub Desktop.
role to submodule

Convert a git folder to a submodule retrospectively

Correct answer

path=roles/
target=openvpn
reponame=ansible-role-${target}
fullpath=${path}${target}

git subtree split --prefix=$fullpath --branch=${target}-only
git rm -rf $fullpath

mkdir $fullpath
pushd $fullpath

hub create gitinsky/$reponame
git init
git remote add origin https://github.com/gitinsky/${reponame}.git
depth=$(dirs| while read dir1 dir2; do printf "$dir1\n$dir2\n"|tr '/' '\n'; done | sort| uniq -u| { while read p; do printf '../'; done; printf '\n'; } |tee /dev/stderr)

git pull $depth ${target}-only
git push origin -u master
popd

git submodule add https://github.com/gitinsky/${reponame}.git $fullpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment