Jump to the navigation menu

Merging without merge commits

Since I posted about optimising for revertability, I've received a few questions about how I avoid merge commits when working with Git.

This is an extract from my .config/git/.config file:

[merge]
    ff = "only"

[pull]
    ff = "only"
    rebase = true

This changes the behaviour of when I run git pull to always include --rebase by default and to only allow fast-forward merges and pulls.

Only allowing fast-forward merges avoids merge commits as Git can just move the pointer for the branch to the latest commit.

If I can't do a fast-forward merge, I need to rebase first to update everything and bring it up to date.

Sometimes, when working in team, merge commits will still creep in sometimes and there are situations where you can only create a merge commit.

In this situation, I can do git merge --ff to allow a merge commit temporarily, but this is the exception instead of the default.

Hint: there's a lot more information on the configuration and arguments if you run and read man git-merge.

When working with online tools such as GitHub and GitLab, I avoid any options like Squash and merge or Create a merge commit and will use rebase options, although I've seen where different commit IDs have been generated when merged in the UI, which is why I prefer to do merges locally.

Or use trunk-based development and don't work on topic branches at all.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.