Why I Prefer Merge Over Rebase

There are many ways to work with git. The workflows vary depending on the size of the team, organization, and on the way of working – is it distributed, is it sprint-based, is it a company, or an open-source project, where a maintainer approves pull requests.

You can use vanilla-git, you can use GitHub, BitBucket, GitLab, Stash. And then on the client side you can use the command line, IDE integration, or stand-alone clients like SourceTree.

The workflows differ mostly in the way you organize you branches and the way you merge them. Do you branch off branches? Do you branch off other people’s branches, which are work-in-progress. Do you push or stay local? Do you use it like SVN (perfectly fine for a single developer on a pet project), or you delve into more “arcane” features like --force-with-lease.

This is all decided by each team, but I’d like to focus on one very debated topic – rebasing vs merging. While you can get tons of results discussing rebasing vs merging, including the official git documentation, it has become more of a philosophical debate, rather than a practical one.

I recently asked a practical question about a rebase workflow. In short, by default rebasing seems not to favour pushing stuff to the central repo. If you do that before rebasing, you’d always need to force-push. And force-pushing may make it very hard for people that are based on your branch. Two questions that you are already asking:

  • Why do you need to push if something isn’t ready? Isn’t it the point of the “D” in “DVCS” to be able to commit locally and push only when ready? Well, even if you don’t use git as SVN, there are still plenty of use-cases for pushing every change to your own feature branch remote – you may be working from different machines, a colleague may want to pick up where you left (before leaving for holiday or falling sick), or even hard drive failures and theft. I think basically you have to push right before you log off, or even more often. THe “distributed” allows for working offline, or even without a central repo (if it goes down), but it is not the major benefit of git.
  • Why would anyone be based on your work-in-progress branch? Because it happens. Sometimes tasks are not split that strictly and have dependencies – you write a piece of functionality, which you then realize should be used by your teammates who work on another task within the same story/feature. You aren’t yet finished (e.g. still polishing, testing), but they shouldn’t wait. Even a single person may want to base his next task on the previous one, while waiting for code review comments. The tool shouldn’t block you from doing this from time to time, even though it may not be the default workflow scenario.

Also, you shouldn’t expect every team member to be a git guru, who rewrites history for breakfast. A basic set of commands (even GUIs) should be sufficient for a git workflow, including the edge cases. Git is complicated and the task of each team is to make it work for them, rather than against them. Probably there is one article for each git command or concept with a title “X considered harmful”, and going through that maze is not trivial for an inexperienced git user. As Linus Torvalds once allegedly said:

Git has taken over where Linux left off separating the geeks into know-nothings and know-it-alls. I didn’t really expect anyone to use it because it’s so hard to use, but that turns out to be its big appeal.

Back to the rebase vs merge – merge (with pull requests) feels natural for the above. You branch often, you push often. Rebase can work in the above use-cases (which I think are necessary). You can force-push after each rebase, and you can make sure your teammates resolve that. But what’s the point?

The practical argument is that the graph that shows the history of the repo is nice and readable. Which I can’t argue with, because I’ve never had a case when I needed a cleaner and better graph. No matter how many merge commits and ugliness there’s in the graph, you can still find your way (if you ever need to). Besides, a certain change can easily be traced even without the graph (e.g. git annotate).

If you are truly certain you can’t go without a pretty graph, and your teammates are all git gurus who can resolve a force-push in minutes, then rebasing is probably fine.

But I think a merge-only workflow is the more convenient way of work that accounts for more real-world scenarios.

I realize this is controversial, and I’m certainly a git n00b (I even use SourceTree rather than the command line for basic commands, duh). But I have used both merge and rebase workflows and I find the merge one more straightforward (after all, force-pushing being part of the regular workflow sounds suspicious?).

Git is the scala of VCS – it gives you many ways to do something, but there is no “right way”. This isn’t necessarily bad, as indeed there are many different scenarios where git can be used. For the ones I’ve had (regular project in a regular company, with a regular semi-automated release & deployment cycle, doing regular agile), I’d always go for merge, with pull requests.

6 thoughts on “Why I Prefer Merge Over Rebase”

  1. Very good article and it nicely sums it up one vs another… I definitely agree with your point of view that merge is more natural IMHO since I can see all the history and I don’t feel comfortable with rebase for the sake of the pretty graph.

  2. The D in DVCS is for “no central repo”, and not for doing work locally. You can work locally in SVN, CVS, what not. The fact of the matter is that everyone elects a central GIT repo, for lack of better ideas. Even then rebasing is better – it gives you the choice of what goes into a release and what doesn’t, for instance.

  3. Git is the scala of VCS – it gives you many ways to do something, but there is no “right way”. – interesting point. I think there’s a right way if you think about it in terms of change lifetime on the Y axis, and quality, on the X. A change presents a risk vs return scenario, return being fixed and risk must be minimized. Risk of change is minimized by running it through a series of checks – unit tests, whatever tests, code reviews, integration with other changes, stability and acceptance checks (SIT and UAT environments), load testing and only then production rollout. Alongside it might bear documentation of known issues, tradeoffs, WTFs, approvals by risk-bearing entities and what have you. This is how you do change, somewhat idealistically. It’s tough to change if you’re programming a car or an algo that can lose you money (read Knight Capital default case). GIT is just better at managing change, the right way.

  4. Look, as I said, I used to enjoy your writing and I still feel you are in good intentions about the software community. I wouldn’t normally do this, but drop me an email if you will – we’re organizing a conference with the likes of Heinz Kabutz and Peter Lawrey already confirmed – I’ll make sure you are treated well at it, is as much as I can say. The offer stands only for you, and only for your good intention.

Leave a Reply

Your email address will not be published. Required fields are marked *