🔀 Fix a Rebase –onto Leaving Orphaned Commits Behind
git rebase –onto newbase oldbase branch replays the commits unique to branch on top of newbase and moves the branch pointer to the result, but the original commits — the ones that existed before the rebase ran — don’t disappear. They simply stop being reachable from any branch, staying alive only through the reflog, which by default expires unreachable entries after 90 days. That’s expected, working-as-designed behavior, but it surprises people who check disk usage or run git gc right after a big rebase and find the old commits are still sitting there, reachable through `git reflog` even though no branch or tag points at them anymore.
🔎 The Problem
git rebase --onto main feature-base feature-branch # feature-branch now points at the rebased commits git log --all --oneline # old pre-rebase commits don't show up here (unreachable from any ref) git reflog # ...but they're still listed here, and `git gc` won't prune them # until the reflog's default 90-day expiry passes
✅ Fix: A Rebase –onto Leaving Orphaned Commits Behind
- Treat this as expected behavior rather than a leak: the old commits are a safety net letting you recover the pre-rebase state with `git reflog` if the rebase went wrong, for as long as the reflog keeps them.
- If you specifically need to reclaim the space or confirm nothing of value was left behind, run `git reflog expire –expire=now –all` followed by `git gc –prune=now` once you’re certain the rebase is correct.
- Before doing that irreversible cleanup, diff the tip of the orphaned commits against your new rebased branch to confirm nothing was dropped or changed unexpectedly during the replay.
🚨 Why This Is Dangerous
- Running an aggressive prune before you’re sure the rebase preserved everything removes your only safety net — once the reflog entries are gone and gc has run, those original commits are not coming back.
A rebase doesn’t delete your old commits — it just stops pointing at them, which is a very different thing until the day you actually need one back.




