From 91beb27b990bdabd41b4f060c692100df7470e40 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 15 May 2024 23:24:07 +0100 Subject: [PATCH] Add daily email for 2024-05-12 Merging without merge commits --- source/_daily_emails/2024-05-12.md | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 source/_daily_emails/2024-05-12.md diff --git a/source/_daily_emails/2024-05-12.md b/source/_daily_emails/2024-05-12.md new file mode 100644 index 00000000..9cc42212 --- /dev/null +++ b/source/_daily_emails/2024-05-12.md @@ -0,0 +1,43 @@ +--- +title: Merging without merge commits +date: 2024-05-12 +permalink: archive/2024/05/12/merging-without-merge-commits +tags: + - software-development + - git +cta: ~ +snippet: | + How to do Git merges without merge commits. +--- + +Since I posted about [optimising for revertability][1], 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: + +```ini +[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][2] and don't work on topic branches at all. + +[1]: {{site.url}}/archive/2024/05/10/optimise-for-revertability +[2]: {{site.url}}/archive/2023/06/17/avoid-git-merge-hell-with-trunk-based-development