1

I've been reading the excellent Pro Git book to gain an understanding of git actions, however there is one scenario illustrated which I cannot understand from what the book is saying.

In the section on Basic Branching and Merging, under the heading Basic Merging, the following example is given.

The before state is this:

                      * master
C0 --- C1 --- C2 --- C4
                \
                 --- C3 --- C5
                             * iss53

A merge is then performed of iss53 into master resulting in this.

                                 * master
C0 --- C1 --- C2 --- C4 ------- C6
                \             /
                 --- C3 --- C5
                             * iss53

This is a good result for the master branch as it now includes the work done on the iss53 branch. Or, in other words, master contains 'everything'.

However, there is talk in various parts of the book about "long running" branches. If iss53 were intended to be such a branch, I see a problem in that further change on that branch does not include anything from the master branch after C2 and so further work is (theoretically) necessitated on future merges.

From reading other questions, the apparent answer is to subsequently merge in the other direction, which would fast-forward iss53 to C6 from where it can once again diverge.

Furthermore, if C4 had not existed at the time of the original merge, it would (by default) have simply fast-forwarded master to C5 which negates the need for the reverse merge.

So these situations have me questioning whether to accept fast-forward merges as a time saving and always reverse-merge non-fast-forwards, or whether there is value in mandating --no-ff and the reverse merge simply for consistency.

Are there reasons not to do the reverse merge, and consequently, perhaps, to always use --no-ff?

As I stated at the beginning, I am just trying to understand git at this stage. I do not have a specific scenario I am working with. I'm still formulating an approach.

zkarj
  • 657
  • 9
  • 23
  • 1
    Many are of the opinion that once the `iss53` branch has been merged into `master`, it should be retired and not used anymore. If you do want to use `iss53` as a long running branch _and_ keep it updated with `master`, then yes you will need to do a reverse merge. – Tim Biegeleisen Mar 01 '23 at 23:46
  • 1
    Fast-forwarding removes the information on when the merge happened and how much was merged at a time (other than in the committer timestamp), which you may or may not care about. – Ry- Mar 02 '23 at 03:03

1 Answers1

1

Are there reasons not to do the reverse merge

Usually you do not merge integration branches (like dev or main or master) to other branches.

Integration branches are branches you are merging to, not from.

If iss53 itself is a long-lived branch, once you have merged it to main/master, you would recreate iss53 on top of main/master, to create additional commits.
But the usual best practice is to create short-lived feature branches, each one dedicated to a specific feature, that you would merge to dev (first-level integration), then merge that same feature branch to main/master if you think it is ready to be integrated and deployed to production.

That is called gitworkflow (one word).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250