tags:

views:

539

answers:

2

I am struggling trying to make sense of using the Git subtree strategy. My intent was to pull some disparate repos together into a little family of toy repos under an umbrella repo. I'm using the subtree strategy detailed here: http://help.github.com/subtree-merge

I am pulling my hair out trying to convince Git that I want to create a branch from one of these subtrees NOT from the root. When I cd into a subtree, create the branch, and then cd back to the root, running git branch from the root clearly indicates the branch was created at the root. Sigh.

I love git/github but it is maddening getting this seemingly routine task to work properly.

Could someone please enlighten me?

+4  A: 

git works at the 'whole' tree level only, so wherever you are in your working tree operations like branch, checkout <branch>, commit all work at the root level.

The subtree merge strategy is a merge strategy to help when you have a repository where one branch has moved a subtree of files to a different place in the repository and another side has made changes to those files in the original locations. It's designed to help merge these two operations in a way that a normal merge strategy would generate more conflicts or leave files in the wrong place.

The subtree merge strategy has no bearing on the way the 'whole tree' operation of git works, so if you want make a branch that is just one subtree of a repository, you need to branch then make a new commit with the other subtrees removed and the tree of interest moved up to the root level.

Given your usage pattern, though, I would recommend that you have long read up on submodules. It may provide functionality that suits what you are trying to achieve.

Charles Bailey
Charles, I tried the submodule route. The problem there is that submodules are just a reference to an external repo. Exactly what I'm trying to avoid. I want the repo to exist self contained within the parent and *NOT* refer to anything else.
dugla
subtree merge strategy is usually used to merge in project which was developed separately, and now is part of larger project (and of course files from such (sub)project should go to subdirectory of superproject, not to top dir of superproject).
Jakub Narębski
I have to confess to only having used subtree merge in toy examples, so thanks for some 'real' world insight.
Charles Bailey
+1  A: 

I recommend apenwarr's git-subtree: http://github.com/apenwarr/git-subtree. Hopefully it gets added to git itself at some point.

Bryan Larsen
Whoa. That does look like what I've been on the lookout for. Thanks for this Bryan.
dugla