13. Git merge strategy

When we merge our PR, by default, git creates a new merge commit
into the destination branch. This is very common method.
I feel, this extra commit is

  • unnecessary and ugly.
  • git history looks messy due to many branches in history graph.

However, there is a better, cleaner, and beautiful way to merge
our code and keep it very leaner without any messy graphs.
Git again rocks!

This is called fast-forward (--ff-only) merging. We can set this into
the GitHub, GitLab, Bitbucket repo settings.

13.1 Github

  • go to the repo -> Click on Settings (GearWheel icon)
    ->Options->Merge Button -> Check only Allow Rebase Merging
  • This ensures, only rebased branches are merged but no merge commit
    gets created upon successful merge.

13.2 GiLab

go to your repo -> settings -> general -> Merge Requests -> Merge Methods -> Fast Forward Merge Just below of above setting, there is option for Squash. 'Squash commits when merging' Choose the option : "Require" Then do click on Save. Ref: https://docs.gitlab.com/ee/user/project/merge_requests/methods/