oliverdavies.uk/source/_daily_emails/2024-05-12.md

1.7 KiB

title date permalink tags cta snippet
Merging without merge commits 2024-05-12 daily/2024/05/12/merging-without-merge-commits
software-development
git
~ How to do Git merges 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.