brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pull.ff only stops git pull from making surprise merge commits

Git
~/tips/tip-git-pull-ff-only

git config --global pull.ff only

Makes git pull refuse to create a merge commit unless it can simply fast-forward.

Everybody has seen a history full of “Merge branch ‘main’ of …” commits that nobody meant to make. They come from git pull quietly merging when your branch and the remote have both moved. One setting makes git ask you first.

git config --global pull.ff only

With this, git pull only goes ahead when the update is a fast-forward, which means your branch has nothing the remote lacks. The manual says it is the same as giving --ff-only on the command line, and that it overrides merge.ff when pulling.

When the branches have diverged, git stops with an error instead of creating a merge commit. That is the moment you decide what you want:

git pull --rebase

puts your commits on top of the new ones, while git pull --no-ff makes the merge on purpose.

Caveat: the error looks scary the first time and scripts that run git pull will fail on a diverged branch. That is the point, but check any automation that updates a checkout before you switch the global setting. The option only affects git pull, not a normal git merge.

Leave out --global to set it for just one repository.

Further reading: git config, pull.ff (Git documentation)

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link