35

I’ve watched some videos on the git-flow scripts and one term that comes up is “back merge” - e.g. hotfix is merged into master and back merged into develop.

I’m assuming back merge is a concept and not a native git command. What exact commands comprise a back merge operation?

mlhDev
  • 2,235
  • 1
  • 22
  • 43
  • 1
    Here's a little [Stack Overflow essay](https://stackoverflow.com/a/65239988/341994) on this topic that might help folks to visualize why a "back merge" is needed after a hotfix. – matt Dec 11 '20 at 19:18

3 Answers3

46

The use of the term "back merge" is usually somewhat arbitrary.

It just means to do a merge, like any other, but in a direction that is "backwards" compared to the normal flow of the branching conventions. If you visualize branches arranged like

master    hotfix    release    dev    feature
  |          |         |        |         |
  |          |         |        |         |
  |          |         |        |         |
  |          |         |        |         |

then changes normally "flow" from right to left - feature to dev to release to master. But while hotfixes are pretty far left - they get created from master - they still have to be merged "to the right" into dev, so some people describe that as merging backwards, or back-merging.

In my opinion, that's not the most compelling use of the term, because it can be read to imply that the opposite merge (from dev to a hotfix branch) were a "forward merge" - but in fact that's something that shouldn't be done. In this case the direction being "backward" is more about the general flow of changes if you visualize the branches in a particular way as above.

A more compelling use of the term is when you have a long-lived feature branch (which itself is something of an anti-pattern in agile processes that are likely to use gitflow; but sometimes you may need one). In that case you periodically should update your long-lived feature from dev, so that the two don't deviate too much leading to a disaster of a merge conflict later. (And this opens up a whole can of worms about "unnecessary" merges, what makes a good history, and git rerere... but I digress.) That can clearly be called a back-merge because the opposite - merging your feature in to dev - is a normal, textbook use of merge in the branch model.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
30

Backmerge is nothing but add your hotfix changes into your current working branch.

Let's say you have two branches Develop and Master
You found any major bug on Master. You fixed it on Master branch itself as a hotfix. Later you need to add your bugfix change into your current working branch i.e Develop branch. so you need to do back-merge like this


  1. git checkout Develop
  2. git merge Master
  3. git push origin Develop
Vrushali Raut
  • 1,130
  • 1
  • 10
  • 20
  • yes, so we simply create a PR like: [ base: Develop <--- compare: MASTER ]. Usually you develop & implement code changes in Develop branch & push them to Master, But in such exceptional scenario of "HotFix", usually a hotfix is a breaking/blocking/critcal code change that saves our day. In this scenario time is vital constraint. Hence, you can't go from Devlop -> Test -> Stage -> Master, instead you make a code change directly on Master & then you do the backmerge, so that other branches are aware of the code change that their successor has. – Aniket Oct 28 '21 at 13:35
9

It's just two ordinary merge commands:

git checkout master
git merge hotfix
git checkout develop
git merge hotfix

You can think of the "normal" flow of commits being from your development branch to master as the work is completed. In a back-merge, the commits are flowing in the opposite direction, from hotfix into your development branch.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • 2
    Generally the last command would actually be `git merge master` (you're "back merging" master back into develop). As others have pointed out, it's an inexact term, but the way I've seen it used. – mgalgs Aug 20 '19 at 20:51
  • This one makes the most sense for me, but instead of `git merge hotfix`, replace with `git merge release` to merge a release branch with the Develop branch – Christopher Carswell Sep 21 '20 at 08:35
  • The first two commands `git checkout master` and `git merge hotfix` is the normal flow. (sending something to production) The last two commands `git checkout develop` and `git merge hotfix` is the back merge flow. (getting something back from hotfix) – Rohit Kumar Shrivastava Jan 18 '22 at 08:43