sunnuntai 16. kesäkuuta 2013

Converting Git submodules to subtrees

While learning to use Vagrant, I've been using git submodules. But git subtrees seems to be a lot better choice, so I wanted to start using them.

So, in my repository, which can be found from https://github.com/jyrkiput/vagrant-jenkins-gerrit, I had following .gitmodules:
[submodule "puppet/modules/jenkins"]
path = puppet/modules/jenkins
url = https://github.com/rtyler/puppet-jenkins.git
[submodule "puppet/modules/java"]
path = puppet/modules/java
url = https://github.com/puppetlabs/puppetlabs-java.git
[submodule "puppet/modules/stdlib"]
path = puppet/modules/stdlib
url = https://github.com/puppetlabs/puppetlabs-stdlib.git
[submodule "puppet/modules/firewall"]
path = puppet/modules/firewall
url = https://github.com/puppetlabs/puppetlabs-firewall.git
[submodule "puppet/modules/apt"]
path = puppet/modules/apt
url = https://github.com/puppetlabs/puppetlabs-apt.git
And with Git 1.8.3.1 installed from with Homebrew (http://brew.sh/).

Unregister all submodules with git submodule deinit
git submodule deinit .
This removes submodule configurations, so each module must be removed. So for each module
git rm puppet/modules/[modulename]
ie.
git rm puppet/modules/jenkins
Commit your changes
git commit -m "Removed submodules"
Add modules as subtrees, so for each module
git-subtree add --prefix=path/to/subtree --squash repository master
ie.
git-subtree add --prefix=puppet/modules/jenkins --squash https://github.com/jenkinsci/puppet-jenkins master
git-subtree will make a commit when a subtree is added, so these are now in your repository

Finally remove .gitmodules for cleaning up things.

The man page of git subtree was really helpful when finding out what to do, and it contains a lot more information.

Ei kommentteja :

Lähetä kommentti