44 lines
1.7 KiB
Markdown
44 lines
1.7 KiB
Markdown
---
|
|
title: Merging without merge commits
|
|
date: 2024-05-12
|
|
permalink: daily/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
|