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, I had following .gitmodules:
[submodule "puppet/modules/jenkins"]
path = puppet/modules/jenkins
url =
[submodule "puppet/modules/java"]
path = puppet/modules/java
url =
[submodule "puppet/modules/stdlib"]
path = puppet/modules/stdlib
url =
[submodule "puppet/modules/firewall"]
path = puppet/modules/firewall
url =
[submodule "puppet/modules/apt"]
path = puppet/modules/apt
url =
And with Git installed from with Homebrew (

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]
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
git-subtree add --prefix=puppet/modules/jenkins --squash 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.