News for hackers. Stuff that matters.
Re:Why is git pull considered harmful? (2013) by sergiosgc on Wednesday March 12, 2014 @10:45AM (#7385878)
I feel tempted to just answer the question using the Betteridge Law of Headlines: Why is git pull considered harmful? It isn't.

- nonlinearities aren't intrinsically bad. If they represent the actual history they are ok.

- accidental reintroduction of commits rebased upstream are the result of wrongly rewriting history upstream. You can't rewrite history when history is replicated along several repos.

- modifying the working directory is an expected result; of debatable usefulness, namely in the face of the behaviour of hg/monotone/darcs/other_dvcs_predating_git, but again not intrinsically bad.

- pausing to review others' work is needed for a merge, again an expected behaviour on git pull

- making it hard to rebase against a remote branch is good. Don't rewrite history unless you absolutely need to. I can't for the life of me understand this pursuit of a (fake) linear history

- Not cleaning up branches is good. Each repo knows what it wants to hold. Git has no notion of master-slave relationships.

Re:Why is git pull considered harmful? (2013) by jenius on Wednesday March 12, 2014 @11:57AM (#7386370)
Ok so let me post an opinion from the other side. I think that histories that represent actual history in git are actually not useful at all. Let's look at an example.

I make a commit that introduces a bug and contains a typo. Someone else points out the bug, so I fix the bug. Then someone else points out the typo so I fix the typo, one small commit for each fix. While this is indeed an accurate depiction of history, having three commits (one broken, and two silly short one character/line changes) in your commit history instead of one commit is not in any way useful here. For anyone reviewing a pull request or doing anything else that involved looking through the history (that's what history is for, right?), this is a waste of time, and unnecessarily sloppy. Or if you need to cherry-pick or bisect, for example, you now have three commits that represent one change, rather than one commit for one change.

Let's say someone makes a pull request to one of my projects for a change they made that ends up having 5 commits fixing things they did wrong initially, that could be 1 or 2 commits. There is zero chance I'm going to say "Ah well, I guess that's an accurate representation of history! Let's merge it!" I'm going to tell them to squash and rebase their commits to clean it up, then force push. And to be honest, I think anyone who didn't do this would be doing it wrong, promoting a messy history in their project.

Generally, this whole debate within git is referred to as whether you should "hide the sausage" or not. Further discussion can be found here, with lots of arguments I didn't touch on at all in this comment: http://sethrobertson.github.io/GitBestPractices/#sausage

Re:Why is git pull considered harmful? (2013) by sergiosgc on Wednesday March 12, 2014 @12:03PM (#7386406)
In the precise case of the bug and typo, you should probably use git commit --amend.

Anyhow, generically, while your changes are local, rewrite history to your hearts content. Have it tell a development story that makes sense. The real important part is: you can rewrite history only while it is private. When you push the commits, never ever rewrite history.

Namely, rebasing is not a replacement for merging.

Re:Why is git pull considered harmful? (2013) by kmowery on Wednesday March 12, 2014 @12:54PM (#7386760)
git commit --amend is rewriting history, just not very much of it. If you --amend after pushing, you run into the exact same problems mentioned before.
Re:Why is git pull considered harmful? (2013) by sergiosgc on Wednesday March 12, 2014 @02:41PM (#7387420)
Yes, of course. I failed to mention that.
Re:Why is git pull considered harmful? (2013) by ender7 on Wednesday March 12, 2014 @02:18PM (#7387279)
Once you push a change to a public repo, you should not change it. It sucks that it's broken, but that's your fault; you should either roll back your change or submit a second change that fixes it. However, you shouldn't rebase your second change onto your first one. There be dragons.

If you want to have a perfect public repo history, you can revert your change, fix it in private, then push the modified version to the public repo.

Re:Why is git pull considered harmful? (2013) by dbaupp on Wednesday March 12, 2014 @04:36PM (#7388208)
"Once you push to a shared branch in public repo" rebasing and force pushing feature branches is OK (how else does one maintain a clean history after code-review?).
Re:Why is git pull considered harmful? (2013) by snth on Wednesday March 12, 2014 @01:07PM (#7386846)
Haha, I think you meant "hide the sausage making".
Re:Why is git pull considered harmful? (2013) by benrhughes on Wednesday March 12, 2014 @04:09PM (#7388002)
ROFL, yes - "hide the sausage" has quite a different meaning. Though you could argue that rebasing is, um, hiding the sausage with history.
Re:Why is git pull considered harmful? (2013) by pierrebai on Wednesday March 12, 2014 @03:40PM (#7387790)
Every times I hear these sort of justification my little rage meter goes up a notch. These arguments are all based on unverified and unncessary optimizations.

* How many times have you read a project history commit by commit? How much time the occasional typo-commit took you to read? The probalbe answer, if measure would be negligible. Yet you're ready to spend time rewiting history. Which can cause real and known time wate as people have to rebase remerge, and sometimes cause all the problem that have been outlined.

* The whole point of bisect is using a logarithmic search into history. The rare typo-fix commit won't affect its runtime. Again, this is wasting time for no measurable effect.

* Stop the micro-fixing commit already in the first place!

But what really annoys me is that all these are the symptoms of a deeper disease: mis-managed repos. This first thing to do if you have the legendary 50GB log show up in your repo is not to rewrite history. The first thing to do is to make an urgent note to review your repo management processes. How did that file get in there in the first place? Are you pulling directly in your main repo!? The correct practice is to always pull into a staging repo and only merge into main if clean. How do you know it's clean? Easy: use the double-staging repo trick: pull into a staging repo make sure everything is shape (human manual process) then pull into another clean-from-main staging repo and diff the history. If the diff is not empty, you know something is wrong. Only when diff are clean do you pull from that staging repo into main.

(BTW, that double staging is only necessary if you allow yourself to do cleanup in the staging repos. If you always insist on clean pull, then all the cleaning up is done elsewhere. This is not always possible / easy /efficient to do on busy repo. And on your private working repo, do as you please, as long as the pull then comes off clean.)

(Also, I recommend doing the same on your private working repo. I always find it easier to have clean copy of the main repo, one staging repo where my own cersion of clean-up history is kept and the real dirty-work repo yet a third repo. The fact that I prefer to work with mercurial which works best by cloning rather than branching pretty much enforce this discipline. It promotes happy collaborations since you never pull into your work repo and you never push from it.)

Re:Why is git pull considered harmful? (2013) by nathanvanfleet on Wednesday March 12, 2014 @04:11PM (#7388018)
The more I read about this stuff the more I realize there are a lot of ways to manage things that fall entirely outside of the actual software that does the management. We're going into the muddy waters of "best practices" but it's interesting to read about different implementations.
Re:Why is git pull considered harmful? (2013) by jenius on Tuesday March 18, 2014 @10:53AM (#7422262)
Hey so think about this -- what if instead of a "staging repo" you just used branches? This is what they are supposed to be used for. In fact, you can make a pull request from a branch, then other developers can review it and the branch can be rebased and cleaned up before it's merged.
Re:Why is git pull considered harmful? (2013) by __david__ on Wednesday March 12, 2014 @02:58PM (#7387534)
> I can't for the life of me understand this pursuit of a (fake) linear history.

Because we, the rebasers, don't consider the repository to be "history".

If you stop thinking of it as history, your whole perspective changes.

It may fool you into thinking that it's history because there are dates everywhere, but it's really just a big collection of ordered changesets.

With that in mind:

> - accidental reintroduction of commits rebased upstream are the result of wrongly rewriting history upstream. You can't rewrite history when history is replicated along several repos.

Of course you can. Your local repo and the remote servers you have access to are malleable and can manipulated however you'd like. I happily force push when the situation calls for it.

However, it does place a burden on everyone else who fetches/pulls from that repo and so one need to take that into consideration. For major screwups (like the 50gb file accidental checkin from the article), it's very, very good that this can happen.

For one of my projects I'm using git-multimail[1] on our "master" repo and it handles force pushes brilliantly (sends out emails with a list of commits removed/added). This is a great way to communicate with the rest of the team when you have a rewrite-after-push culture.

[1] https://github.com/mhagger/git-multimail

Re:Why is git pull considered harmful? (2013) by sergiosgc on Wednesday March 12, 2014 @06:29PM (#7388846)
If there is such a thing as rebasers, git-rebase man page reading should be mandatory for admittance:

„Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea: anyone downstream of it is forced to manually fix their history. This section explains how to do the fix from the downstream’s point of view. The real fix, however, would be to avoid rebasing the upstream in the first place.“--https://www.kernel.org/pub/software/scm/git/docs/git-rebase....

Re:Why is git pull considered harmful? (2013) by jheriko on Wednesday March 12, 2014 @11:29AM (#7386149)
>I can't for the life of me understand this pursuit of a (fake) linear history.

me too... i really enjoy history being immutable and accurate. all of the arguments i've heard for pruning history tend to boil down to ease of use - but i strongly suspect its a spurious argument, and that the perceived ease of use stems from not even having considered the alternatives and following the crowd (which is afaik why most people using git are using it broadly)

Re:Why is git pull considered harmful? (2013) by jarrett on Wednesday March 12, 2014 @11:55AM (#7386354)
My policy is this: You may rewrite commits you've made to your local repo since your last push, but you may never rewrite a commit that has been pushed.

Your teammates don't care much if you do the former. From their perspective, it's the same as if you'd committed at different points in your development process. So long as your final, rewritten history doesn't violate your team's preferences as to the granularity of commits, you're fine.

So go ahead and rewrite your local, un-pushed changes if you feel it makes the history more organized.

But if you do the latter--rewriting history that has been pushed--you're in trouble. All developers should be able to assume that the history in the central repo is immutable. Most likely, they will rely on that assumption.

Re:Why is git pull considered harmful? (2013) by icambron on Wednesday March 12, 2014 @12:02PM (#7386402)
I'd like to separate private from local. I allow for private branches on the central repo to be mutable. (By "private", I just mean marked in such a way that its clear it's owned by a particular user.) Otherwise, people end up keeping their changes local until they're ready to merge and you lose the backup aspect of git. But no one should be merging private branches (regardless of location) without their author giving an explicit OK anyway, so this doesn't seem dangerous.
Re:Why is git pull considered harmful? (2013) by jarrett on Wednesday March 12, 2014 @12:10PM (#7386458)
That's a good point. How do you synchronize history rewriting across the local and remote copies of the private branches? Do you have a formalized way to ensure it doesn't get messed up?
Re:Why is git pull considered harmful? (2013) by benesch on Wednesday March 12, 2014 @01:46PM (#7387083)
If you enforce a convention that private branches start with the developers initials (nb-restructre-everything), and that developers can force-push only their own branches, you can rely on each developer to keep their remote up-to-date.

You can even rewrite a branch shared between developers that hasn't been merged mainline: once it's done, have one of the developers create a duplicate branch in their own private namespace, and rebase and merge that.

Accidents happen, though. If you want to be guaranteed safety, enforce that every developer have their own remote fork. They can rebase at-will on their own fork, and submit pull requests to the mainline repository. (If you're using GitHub, this is dead simple, since you can open pull requests across forks.) This method introduces a fair bit of hassle and overhead for a smallish team, though.

Re:Why is git pull considered harmful? (2013) by acchow on Wednesday March 12, 2014 @01:38PM (#7387040)
Where I work, you prefix the name of your branch with your username, like "acchow/new-feature". This tells other people "do not touch this branch because its history will be changed by acchow".

Alternatively, if you use github, you can set access controls on forks to read-only and send pull requests from your fork to the main repo.

Re:Why is git pull considered harmful? (2013) by icambron on Wednesday March 12, 2014 @01:58PM (#7387155)
What benesch said, basically: just force push your own branches. Have to be careful if you work from multiple computers, though.
Re:Why is git pull considered harmful? (2013) by ngoldbaum on Wednesday March 12, 2014 @12:12PM (#7386477)
Incidentally this is the enforced-by-design behavior of mercurial with respect to history modifying actions.
Re:Why is git pull considered harmful? (2013) by jheriko on Thursday March 13, 2014 @07:52AM (#7391192)
> All developers should be able to assume that the history in the central repo is immutable. Most likely, they will rely on that assumption.

Amen.

Re:Why is git pull considered harmful? (2013) by dazmax on Wednesday March 12, 2014 @02:02PM (#7387180)
It's not just the excessive number of merges that git pull creates – they also have the wrong orientation.

Since pull merges others' commits on top of yours, the diff it creates is full of their changes but has your name on it, which clouds blame and history and makes conflict resolution more difficult. I think this is something git should fix.

See this article about merge direction: http://tech.novapost.fr/merging-the-right-way-en.html

Re:Why is git pull considered harmful? (2013) by InclinedPlane on Wednesday March 12, 2014 @04:49PM (#7388306)
> I can't for the life of me understand this pursuit of a (fake) linear history

Git is a highly useful tool but it's also an incredibly flawed one, especially in that most critical aspect for all software: the merger of technical and human concerns.

Git is a useful set of source control primitives but it's lacking the cohesion necessary to make it a truly great tool. The fact that it's so popular is largely a consequence of the state of competition rather than its own internal awesomeness. One consequence of this is that instead of a robust, well thought out set of use cases which mesh well with various real-world applications git instead has a few hacky workarounds for certain scenarios. This results in the inevitable wobbliness of any system built on top of hacks and leaky abstractions. Rebasing being perhaps the ultimate example of just that.

Personally I think history should largely be treated as immutable (it's funny how in programming we've become more and more attuned to the values of immutability while in source control we've become more amenable to mutability) but with some sort of system designed to make viewing history easier for the user (lots of other source control products have precisely this, it's sort of silly that git doesn't).

Re:Why is git pull considered harmful? (2013) by tvon on Wednesday March 12, 2014 @10:53AM (#7385924)
Perhaps you should post a response to keep things from being so one-sided.
Re:Why is git pull considered harmful? (2013) by sergiosgc on Wednesday March 12, 2014 @11:15AM (#7386046)
Thanks for the suggestion. I just posted the answer there [1].

[1] http://stackoverflow.com/a/22355851/383868

Re:Why is git pull considered harmful? (2013) by mcv on Wednesday March 12, 2014 @11:00AM (#7385961)
Yeah, I'd vote that answer up. If sergiosgc won't post it on stackoverflow, maybe I will. (My notice my comment there has already been upvoted quite a bit.)
Re:Why is git pull considered harmful? (2013) by Linell on Wednesday March 12, 2014 @10:59AM (#7385952)
Someone definitely should. For those of us who aren't super experienced, it would be good to hear both sides of the story in the same place.
Re:Why is git pull considered harmful? (2013) by haptiK on Wednesday March 12, 2014 @11:09AM (#7386006)
I agree. This retort should be posted for a balanced view of the topic.