Git rebase vs git merge?

To complement my own answer mentioned by TSamper a rebase is quite often a good idea to do before a merge, because the idea is that you integrate in your branch Y the work of the branch B upon which you will merge. But again, before merging, you resolve any conflict in your branch (i.e. : "rebase", as in "replay my work in my branch starting from a recent point from the branch B) If done correctly, the subsequent merge from your branch to branch B can be fast-forward a merge impact directly the destination branch B, which means the merges better be trivial, otherwise that branch B can be long to get back to a stable state (time for you solve all the conflicts) the point of merging after a rebase?

In the case that I describe, I rebase B onto my branch, just to have the opportunity to replay my work from a more recent point from B, but while staying into my branch In this case, a merge is still needed to bring my "replayed" work onto B The other scenario ( described in Git Ready for instance), is to bring your work directly in B through a rebase (which does conserve all your nice commits, or even give you the opportunity to re-order them through an interactive rebase) In that case (where you rebase while being in the B branch), you are right: no further merge is needed: A git tree at default when we have not merged nor rebased we get by rebasing: That second scenario is all about: how do I get new-feature back into master My point, by describing the first rebase scenario, is to remind everyone that a rebase can also be used as a preliminary step to that (that being "get new-feature back into master") You can use rebase to first bring master "in" the new-feature branch: the rebase will replay new-feature commits from the HEAD master, but still in the new-feature branch, effectively moving your branch starting point from an old master commit to HEAD-master That allows you to resolve any conflicts in your branch (meaning, in isolation, while allowing master to continue to evolve in parallel if your conflict resolution stage takes too long) Then you can switch to master and merge new-feature (or rebase new-feature onto master if you want to preserve commits done in your new-feature branch) So: rebase vs. merge" can be viewed as two ways to import a work on, say, master But "rebase then merge" can be a valid workflow to first resolve conflict in isolation, then bring back your work.

To complement my own answer mentioned by TSamper, a rebase is quite often a good idea to do before a merge, because the idea is that you integrate in your branch Y the work of the branch B upon which you will merge. But again, before merging, you resolve any conflict in your branch (i.e. : "rebase", as in "replay my work in my branch starting from a recent point from the branch B) If done correctly, the subsequent merge from your branch to branch B can be fast-forward.

A merge impact directly the destination branch B, which means the merges better be trivial, otherwise that branch B can be long to get back to a stable state (time for you solve all the conflicts) the point of merging after a rebase? In the case that I describe, I rebase B onto my branch, just to have the opportunity to replay my work from a more recent point from B, but while staying into my branch. In this case, a merge is still needed to bring my "replayed" work onto B.

The other scenario (described in Git Ready for instance), is to bring your work directly in B through a rebase (which does conserve all your nice commits, or even give you the opportunity to re-order them through an interactive rebase). In that case (where you rebase while being in the B branch), you are right: no further merge is needed: A git tree at default when we have not merged nor rebased we get by rebasing: That second scenario is all about: how do I get new-feature back into master. My point, by describing the first rebase scenario, is to remind everyone that a rebase can also be used as a preliminary step to that (that being "get new-feature back into master").

You can use rebase to first bring master "in" the new-feature branch: the rebase will replay new-feature commits from the HEAD master, but still in the new-feature branch, effectively moving your branch starting point from an old master commit to HEAD-master. That allows you to resolve any conflicts in your branch (meaning, in isolation, while allowing master to continue to evolve in parallel if your conflict resolution stage takes too long). Then you can switch to master and merge new-feature (or rebase new-feature onto master if you want to preserve commits done in your new-feature branch).

So: "rebase vs. merge" can be viewed as two ways to import a work on, say, master. But "rebase then merge" can be a valid workflow to first resolve conflict in isolation, then bring back your work.

By the sound of your answer, it almost seems that one must still merge even after a rebase. If I have a master branch, and a master-feature branch. I will create a feature in master-feature, then want to have that feature available in master.

If I rebase, it'll take all say, N commits I made in master-feature and show the history in master. What's the point of merging after a rebase? – Coocoo4Cocoa Apr 29 '09 at 20:57 merge after rebase is a trivial fast forward without having to resolve conflicts.

– obecalp Apr 30 '09 at 19:32 1 @obelcap: Indeed, this is kind of the idea: you take all the problem-conflict in your environment (rebase master within your new-feature branch), and then co master, merge new-feature: 1 pico-second (fast-forward) if master had no evolutions – VonC Apr 30 '09 at 21:29 4 Rebase is also nice because once you do eventually merge your stuff back into master (which is trivial as already described) you have it sitting at the "top" of your commit history. On bigger projects where features may be written but merged several weeks later, you don't want to just merge them into the master because they get "stuffed" into the master way back in the history. Personally I like being able to do git log and see that recent feature right at the "top."

Note the commit dates are preserved - rebase doesn't change that information. – Sean Schofield Sep 3 '09 at 14:11 1 @Joe: yes but it is bad practice to rebase what has already been pushed, or what has been fetched. So in practice, no that shouldn't be the case.

– VonC Aug 15 at 18:11.

Short version: - Merge says take all the changes in one branch and merge them into another branch in one big commit - Rebase says I want the point at which I branched to move to a new starting point So when do you use either one. Let's say you have created a branch for the purpose of developing a single feature. When you want to bring those changes back to master, you probably want merge (you don't care about maintaining all of the interim commits).

A second scenario would be if you started doing some development and then another developer made an unrelated change. You probably want to pull and then rebase to base your changes from the current version from the repo.

1 +1 I really like your "short version". – sleske Oct 9 at 18:21.

Merge means: Create a single new commit that merges my changes into the destination. Rebase means: Create a whole new series of commits, using my current set of commits as hints. In other words, calculate what my changes would have looked like if I had started making them from the point I'm rebasing on to.

After the rebase, therefore, you might need to re-test your changes and during the rebase, you would possibly have a few conflicts. Given this, why would you rebase? Just to keep the development history clear.

Let's say you're working on feature X and when you're done, you merge your changes in. The destination will now have a single commit that would say something along the lines of "Added feature X". Now, instead of merging, if you rebased and then merged, the destination development history would contain all the individual commits in a single logical progression.

This makes reviewing changes later on much easier. Imagine how hard you'd find it to review the development history if 50 developers were merging various features all the time. That said, if you have already pushed the branch you're working on upstream, you should not rebase, but merge instead.

For branches that have not been pushed upstream, rebase, test and merge. Another time you might want to rebase is when you want to get rid of commits from your branch before pushing upstream. For example: Commits that introduce some debugging code early on and other commits further on that clean that code up.

To complement my own answer mentioned by TSamper.

By the sound of your answer, it almost seems that one must still merge even after a rebase. If I have a master branch, and a master-feature branch. I will create a feature in master-feature, then want to have that feature available in master.

If I rebase, it'll take all say, N commits I made in master-feature and show the history in master. What's the point of merging after a rebase? – Coocoo4Cocoa Apr 29 '09 at 20:57 1 merge after rebase is a trivial fast forward without having to resolve conflicts.

– obecalp Apr 30 '09 at 19:32 1 @obelcap: Indeed, this is kind of the idea: you take all the problem-conflict in your environment (rebase master within your new-feature branch), and then co master, merge new-feature: 1 pico-second (fast-forward) if master had no evolutions – VonC Apr 30 '09 at 21:29 4 Rebase is also nice because once you do eventually merge your stuff back into master (which is trivial as already described) you have it sitting at the "top" of your commit history. On bigger projects where features may be written but merged several weeks later, you don't want to just merge them into the master because they get "stuffed" into the master way back in the history. Personally I like being able to do git log and see that recent feature right at the "top."

Note the commit dates are preserved - rebase doesn't change that information. – Sean Schofield Sep 3 '09 at 14:11 1 @Joe: yes but it is bad practice to rebase what has already been pushed, or what has been fetched. So in practice, no that shouldn't be the case.

– VonC Aug 15 at 18:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions