O'Reilly logo
  • Peter Bruhn thinks this is interesting:

Okay, jokes aside, there's no magic in Git; it simply won't delete unreachable commits, at least not immediately. It makes some housekeeping automatically at a given time, as it has some powerful garbage collection features (look at the git gc command help page if you are curious; I want you to remember that any Git command, followed by the --help option, will open for you the internal man page for it).


Cover of Git Essentials - Second Edition


Remove all unreachable objects: git gc --prune=now

But beware that an object is not unreachable if it is still referenced in the reflog. To remove the references do:

git reflog expire --expire-unreachable=now --all