Monday, June 03, 2013

git subtree module, with .gittrees config file

I have written about the git subtree module before.
It has been improved, to allow defining your subtrees and imported projects in a config file, in order to update them without having to specify the repo url and branch every time you push to or pull from an imported project.

So, first you need to setup the subtree :

$git subtree add --prefix=other_project \
     git://github.com/your_tree/your_project.git master

It imports the master branch of a git repository located in git://github.com/your_tree/your_project.git into the folder other_project of your git repo.

A file .gittrees in the root folder of your git repo is created :

[subtree "other_project"]
    url = git://github.com/your_tree/your_project.git
    path = other_project
    branch = master

With the subtree being defined in .gittrees, you can make changes to this imported project and you want to push them back to the original project, you can use this :

$git subtree push --prefix=other_project

Or if you want to update the imported project with changes from the original project, you can use this :

$git subtree pull --prefix=other_project

You can also push all changes in imported projects to the original projects, with

$git subtree push-all

It will push all changes to projects that are defined in the .gittrees config file.
Pull changes from all defined subprojects is done with :

$git subtree pull-all

BTW : All subtree commands must be run in the root folder of your git repo.

BTW2: the subtree module is not part of the core git package. So if you want to use it, you will have to install the module first.

Clone the subtree project :

$git clone https://github.com/helmo/git-subtree

In the git-subtree directory, run as root :

#./install.sh

This will copy the git subtree module to the git script folder. You can now use the git subtree module.

3 comments:

Unknown said...

This looks great! Do you know if this is likely to make it into git proper? I see there have been commits pending for this for quite some time.

Dieter Adriaenssens said...

Herman van Rink, who did some modifications to git-subtree and introduced the .gittrees config file, tried to get it incorporated in git, but this stalled. The git maintainers required a cleaned up git history and some tests, but Herman didn't have time to do this.

Paul Campbell started working on it, but activity halted a few months ago.

So, I'm not sure about current status. But it would be great if someone (or some people) would pick up the work that was started and try to get this nice module into git.

E-mail thread, for reference.

enorl76 said...

Hey, I ran into your post, where git subtree module now exists in the main code, but .gittrees file doesn't seem to exist... did that feature stick?