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: git rebase --update-refs moves your stacked branches along

Git
~/tips/tip-git-rebase-update-refs

git rebase --update-refs main

Rebases a branch and also moves the branches stacked underneath it.

When branches are stacked on each other, rebasing the top one leaves every lower branch pointing at the old commits. --update-refs moves them along in the same rebase.

Say feature-b sits on feature-a, which sits on main, and main has moved on. Rebase the top branch with the flag:

git switch feature-b
git rebase --update-refs main

The docs describe it as automatically force-updating any branches that point to commits that are being rebased. At the end Git lists what it moved, like this:

Updated the following refs with --update-refs:
	refs/heads/feature-a

Now feature-a points at its rebased commit and the stack is still a stack. Without the flag, feature-a would keep the old commits and you would have to rebase it separately. To make the flag the default:

git config --global rebase.updateRefs true

With that set, --no-update-refs turns it off for one run.

Two caveats. The docs say any branches that are checked out in a worktree are not updated this way, so if feature-a is open in another worktree, move it yourself afterwards. And because the branches are force-updated, a branch you already pushed will have diverged from its remote copy. Pushing it again needs git push --force-with-lease, so think about who else uses that branch first.

Further reading: git-rebase documentation

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