
Git Subtree merged into mainline git - moonboots
https://github.com/gitster/git/commit/634392b26275fe5436c0ea131bc89b46476aa4ae
======
sciurus
If you want to know what the git subtree command is, see
<http://apenwarr.ca/log/?m=200904#30>

~~~
ajray
Additionally useful: Text file explaining the command and usage (from the
commit):
[https://github.com/gitster/git/blob/634392b26275fe5436c0ea13...](https://github.com/gitster/git/blob/634392b26275fe5436c0ea131bc89b46476aa4ae/contrib/subtree/git-
subtree.txt)

Examples are at the bottom.

------
zbowling
Subtree > Submodule in so many ways. Git submodule is a mess and now a legacy
of git.

I've been been using subtree in a fork of Git personally but can't (safely)
use it at work with everyone else (still use submodules there).

This is going to be a problem for github for reasons I put in my blog a few
months back: <http://zbowling.github.com/blog/2011/11/25/github/>

Because Github has their explicit, top down, a-fork-is-only-a-fork-by-
clicking-the-fork-button kind of graph between projects, using subtree won't
work easily with their online tools to do pull-requests and see the network
graph of forks.

Basically my repo is going to have the histories of 7 different projects
combined in one repo and from that single repo I will be pushing back changes
to all 7 (and others versions of those 7). Github's pull request feature is
going to have trouble with that concept because they make the invalid
assumption of a single upstream.

There are work arounds for sure like pushing your changes to a staging repo
before finally doing a pull-request upstream but that is cumbersome. I'll
probably write a shell script to automate it.

~~~
jpeterson
> Git submodule is a mess and now a legacy of git.

I hear this kind of thing all the time, but I don't understand why. I've never
had any problem whatsoever with git submodule. Can you elaborate a bit on what
you mean by this?

~~~
primatology
Off the top of my head:

Ever tried removing a submodule? Why is there no git submodule rm? (No, "it's
confusing" is not a valid argument.)

If the pull fails (say, from the wrong protocol), you end up with a half-baked
submodule. Impossible to move, impossible to remove, impossible to update
unless you dive into the config.

Misspell the folder you wanted the submodule in? That sucks. Go delete it from
two separate locations, and try again!

~~~
Confusion
If that is the worst problem -- one that is easy to solve and easy to repeat
the few times you need it -- then the more love for submodules. I'll take that
over any other available solution any day (I don't count subtrees as
'available' yet).

------
avar
It's been merged into the contrib/ directory, so it's not installed by
default. Saying it's merged into the mainline has the connotation that it's
available like any other tool, it isn't.

------
sophacles
So this looks pretty awesome. I can see myself using it a lot. There is one
workflow that I do with submodules, that i don't see how to do in subtrees:

clone a repo to the target dir. Add it as a submodule. Decide to play with a
branch of the submodule, so switch to that branch in the cloned repo. Then if
i decide to work with that, update my submodules, otherwise switch back.

Is that sort of workflow available in subtrees? How do I do it?

------
antidoh
I've never used git in-the-large, which may be why I don't understand:

Why must some other library/module be part of _my_ project? Why not reference
and maintain the external lib/mod externally? We've been doing that for
decades. It seems a solved problem.

Bringing an external library within the fold of your project feels like
unnecessary coupling.

~~~
eropple
Dependency control it is a solved problem. Which is why SVN has externals, Hg
has hgsubs, and Git has submodules and now subtrees. This isn't a git-in-the-
large problem, it's an almost-any-nontrivial-project problem. It only seems
unnecessary 'till you've had it and tried to live without it.

Bringing other libraries into my project is beneficial because then my build
system is able to wrangle those just as easily as my code. (And it's also
simply useful in the case where I've written both modules but maintain a
separation for whatever reason--one is an open-source project and the other is
not, whatever--to be able to make changes to one from within the other, run
the tests for the submodule, and push it up to staging or upstream, without
having to leave my current project.)

~~~
lmm
Sometimes when I'm at work I forget that not all languages have maven.

~~~
eropple
I really like maven (and run my own repo for my own projects), but it has its
own problems in the latter case I described.

------
buddydvd
Here's a blog post that illustrates how Git Subtree works in a visual way:
[http://psionides.eu/2010/02/04/sharing-code-between-
projects...](http://psionides.eu/2010/02/04/sharing-code-between-projects-
with-git-subtree/)

So, to avoid duplicate commits, you'd either have to rebase the main branch or
squash the commits before adding it back to the subtree (and lose history)?

------
parbo
Maybe I'm stupid, but gitster/git doesn't sound like the mainline for git.

~~~
gerrit
It's the account of Junio C Hamano who is the main maintainer of git

~~~
zbowling
and the changes are now also in git/git

------
adig
I've been trying out git subtree and I understand it's advantages. But I've
wondered if there's a way to use it without adding the merge commits to the
timeline when I update the subtree repository. Something similar to what git
rebase does. (Maybe this is a dumb question and I'm not using git subtree
right) :)

------
etherealG
Honestly I hope they actually do what the article title is suggesting and
bring subtree into mainline. Congrats on making contrib Avery.

------
zoul
Good explanations of subtree merge:

    
    
        http://progit.org/book/ch6-7.html
        http://help.github.com/subtree-merge/

~~~
mkilling
git-subtree is not the same as a subtree merge. The author himself likes to
point that out. A subtree merge is a one-time operation. git-subtree, on the
other hand, enables you to continue to merge in upstream changes. You can also
split the subtree (including it's history) from your repo and make it a
standalone repository again.

~~~
zoul
Thank you for the clarification. Quoting the author:

“[Subtrees] are also not to be confused with using the subtree merge strategy.
The main difference is that, besides merging the other project as a
subdirectory, you can also extract the entire history of a subdirectory from
your project and make it into a standalone project. Unlike the subtree merge
strategy you can alternate back and forth between these two operations. If the
standalone library gets updated, you can automatically merge the changes into
your project; if you update the library inside your project, you can ‘split’
the changes back out again and merge them back into the library project.”

[https://github.com/apenwarr/git-subtree/blob/master/git-
subt...](https://github.com/apenwarr/git-subtree/blob/master/git-subtree.txt)

I guess I will have to get used to the idea that linking external repositories
is harder than Subversion externals :) Which have serious limitations, I know,
but at least they are _so_ simple.

------
MBlume
Reading the docs now, this looks like excellent work. Thanks to everyone
involved =)

------
ajray
I hope to see Android's 'repo' tool improved to (optionally) make use of this.

