News for hackers. Stuff that matters.
Re:Git Subtree merged into mainline git by sciurus on Thursday May 03, 2012 @10:56PM (#3926801)
If you want to know what the git subtree command is, see http://apenwarr.ca/log/?m=200904#30
Re:Git Subtree merged into mainline git by ajray on Friday May 04, 2012 @05:21AM (#3927640)
Additionally useful: Text file explaining the command and usage (from the commit): https://github.com/gitster/git/blob/634392b26275fe5436c0ea13...

Examples are at the bottom.

Re:Git Subtree merged into mainline git by Groxx on Thursday May 03, 2012 @11:40PM (#3926906)
Way more useful than the linked article. Many thanks.
Re:Git Subtree merged into mainline git by zbowling on Thursday May 03, 2012 @11:38PM (#3926897)
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.

Re:Git Subtree merged into mainline git by jpeterson on Friday May 04, 2012 @12:08AM (#3926960)
> 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?

Re:Git Subtree merged into mainline git by primatology on Friday May 04, 2012 @12:15AM (#3926981)
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!

Re:Git Subtree merged into mainline git by Confusion on Friday May 04, 2012 @02:36AM (#3927349)
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).
Re:Git Subtree merged into mainline git by nodemaker on Friday May 04, 2012 @12:57AM (#3927098)
Yes these problems suck.

Sometimes I have deleted my entire repository and cloned it again to update the submodules just because I changed the .gitmodules file.

Note: This actually takes less commands than messing around with .git/config.

Re:Git Subtree merged into mainline git by SkyMarshal on Friday May 04, 2012 @11:47AM (#3928899)
Speaking of git submodule rm, here's a basic script I use for that [1], based on Stackoverflow's answer [2].

1. https://github.com/byrongibson/scripts/blob/master/git-rm-su...

2. http://stackoverflow.com/questions/1260748/how-do-i-remove-a...

Re:Git Subtree merged into mainline git by zbowling on Friday May 04, 2012 @12:43AM (#3927062)
Ever had an upstream gitsubmodule move or shut down? I can't go back 6 months in my SCM and rebuild exactly what I had because the repo is gone now. This is bad and against the concept of having an SCM in the first place.

There is a horrible habit of people forking projects on github just so their submodule stay stable. It's broken.

Re:Git Subtree merged into mainline git by pyre on Friday May 04, 2012 @01:04AM (#3927111)

  > There is a horrible habit of people forking
  > projects on github just so their submodule
  > stay stable. It's broken.
People are forking projects on github in that way because it's a quick, easy, cheap way to create a mirror/hosted copy of the repository they want to use.

I don't see how this is an example of how git-submodule is broken. If you want to use someone else's code, that is under someone else's control in your repository without creating your own backup of said code, then you're the one taking the risk by not creating said backup.

If the git-submodule is mission-critical to you then you should either:

1. Always keep a separate mirror of the 3rd party repo.

or

2. Mirror the 3rd party repo to a hosted location, so that your submodule can point to the mirror instead of the source (basically creating a caching layer under your control).

This is no different than the guy that keeps all of his email in Gmail, then complains because Google shut down his account that 'email is broken' because it's possible for this to happen.

Re:Git Subtree merged into mainline git by zbowling on Friday May 04, 2012 @06:47AM (#3927837)
Sure. Why I explained the work around. Subtree includes the full history of the other project without work-arounds
Re:Git Subtree merged into mainline git by pyre on Friday May 04, 2012 @12:33PM (#3929162)
subtree also includes the full history of the other project in your project's history unless you squash all of the commits (and if you squash them, then you haven't stored the full history). There might also be licensing reasons for wanting to keep the repositories separate, but not.
Re:Git Subtree merged into mainline git by Confusion on Friday May 04, 2012 @02:34AM (#3927344)
Which is why you should only use submodules with repositories under your control. At my work we happily use git submodules. Much better than svn externals and much better than any alternative that existed so far.
Re:Git Subtree merged into mainline git by nodemaker on Friday May 04, 2012 @12:53AM (#3927086)
>There is a horrible habit of people forking projects on github just so their submodule stay stable. It's broken.

Yes I do this and I hate doing it!

Re:Git Subtree merged into mainline git by avar on Friday May 04, 2012 @04:02AM (#3927522)
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.
Re:Git Subtree merged into mainline git by sophacles on Friday May 04, 2012 @02:38AM (#3927356)
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?

Re:Git Subtree merged into mainline git by antidoh on Friday May 04, 2012 @12:40AM (#3927053)
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.

Re:Git Subtree merged into mainline git by eropple on Friday May 04, 2012 @12:44AM (#3927067)
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.)

Re:Git Subtree merged into mainline git by lmm on Friday May 04, 2012 @04:58AM (#3927602)
Sometimes when I'm at work I forget that not all languages have maven.
Re:Git Subtree merged into mainline git by eropple on Friday May 04, 2012 @10:07AM (#3928391)
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.
Re:Git Subtree merged into mainline git by nodemaker on Friday May 04, 2012 @12:49AM (#3927076)
Yes exactly.

After you have divided your project into independent modules you have agreed that the changes in these modules are going to have minimal impact on each other, then what exactly is the point of merging the history of all those changes?.In my use case that would actually create a bigger mess.

Now I think this could perhaps be useful if there are modules that I have forked from elsewhere and the fork is going to be used in my project only.Although even then I dont see any downside of using submodules.

The downside of submodules is lack of good commands .For example a command to check out a different branch of each of my submodules - the branch which is used in this project.This could be done using the -for-each tag but its not trivial.

EDIT:In this thread zbowling makes a great argument against submodules.

There is a horrible habit of people forking projects on github just so their submodule stay stable

Re:Git Subtree merged into mainline git by Confusion on Friday May 04, 2012 @02:32AM (#3927339)
For instance because you have componentized your product into different repositories, use different combinations of the components in different projects, but are still actively developing many of them simultaneously on each of those projects. Having to build, deploy and fetch gems (or whatever other method of distribution your language uses) is cumbersome if development is still really active.

I don't think you should ever want to bring unreliable external components, like a random github project that you aren't actively contributing to, into your tree like that.

Re:Git Subtree merged into mainline git by antidoh on Friday May 04, 2012 @08:51AM (#3928129)
"For instance because you have componentized your product into different repositories, use different combinations of the components in different projects, but are still actively developing many of them simultaneously on each of those projects."

Funny, I thought this was the beginning of an argument agreeing with me. :)

Re:Git Subtree merged into mainline git by pyre on Friday May 04, 2012 @01:12AM (#3927139)
One example would be:

  * https://github.com/altercation/solarized

  * https://github.com/altercation/vim-colors-solarized
The vim-colors-solarized repo is a subtree of the solarized repo. This is mostly a convenience for vim users that use something like pathogen + git-submodule to keep their plugins up-to-date. This way you can create a submodule @ ~/.vim/bundle/vim-colors-solarized and it would be the root of the bundle tree. If the vim colorscheme was only part of the larger repo, then users would be forced to create their own repos, or else do something like:

  git submodule .vim/bundle/.vim-colors-solarized
  ln -s .vim-colors-solarized/vim-colors-solarized .vim/bundle/
Re:Git Subtree merged into mainline git by adrianmsmith on Saturday May 05, 2012 @04:28PM (#3933185)
It's important to not only reference an external project (e.g. library) but also to reference a particular version of that library. (e.g. newer versions could remove deprecated methods which you are using, i.e. which weren't deprecated when you wrote your code.)

Different versions of your code could rely on different versions of the library (e.g. you update your code to a newer version of the library.) So which version of the library you rely on also needs to be version-controlled.

Re:Git Subtree merged into mainline git by lucian1900 on Friday May 04, 2012 @05:11AM (#3927623)
It makes it a little easier to maintain one or more forks of some library. Without submodules, you must have a separate repo for that, and there's no clear connection to the repo of your particular project.

This gets even more fun when you have a second project that needs an incompatible fork of the same library.

Re:Git Subtree merged into mainline git by buddydvd on Friday May 04, 2012 @06:26AM (#3927796)
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...

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)?

Re:Git Subtree merged into mainline git by parbo on Friday May 04, 2012 @02:52AM (#3927391)
Maybe I'm stupid, but gitster/git doesn't sound like the mainline for git.
Re:Git Subtree merged into mainline git by gerrit on Friday May 04, 2012 @03:27AM (#3927449)
It's the account of Junio C Hamano who is the main maintainer of git
Re:Git Subtree merged into mainline git by zbowling on Friday May 04, 2012 @06:43AM (#3927827)
and the changes are now also in git/git
Re:Git Subtree merged into mainline git by adig on Friday May 04, 2012 @03:45AM (#3927480)
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) :)
Re:Git Subtree merged into mainline git by etherealG on Friday May 04, 2012 @04:18AM (#3927553)
Honestly I hope they actually do what the article title is suggesting and bring subtree into mainline. Congrats on making contrib Avery.
Re:Git Subtree merged into mainline git by zoul on Friday May 04, 2012 @01:14AM (#3927144)
Good explanations of subtree merge:

    http://progit.org/book/ch6-7.html
    http://help.github.com/subtree-merge/
Re:Git Subtree merged into mainline git by mkilling on Friday May 04, 2012 @03:14AM (#3927433)
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.
Re:Git Subtree merged into mainline git by zoul on Friday May 04, 2012 @03:28AM (#3927451)
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...

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.

Re:Git Subtree merged into mainline git by MBlume on Friday May 04, 2012 @02:27AM (#3927325)
Reading the docs now, this looks like excellent work. Thanks to everyone involved =)
Re:Git Subtree merged into mainline git by ajray on Friday May 04, 2012 @05:18AM (#3927633)
I hope to see Android's 'repo' tool improved to (optionally) make use of this.