Skip to content

Instantly share code, notes, and snippets.

@ndkhoa
Last active September 13, 2025 23:46
Show Gist options
  • Select an option

  • Save ndkhoa/5efec3c3990d0e981b47b9968c093797 to your computer and use it in GitHub Desktop.

Select an option

Save ndkhoa/5efec3c3990d0e981b47b9968c093797 to your computer and use it in GitHub Desktop.
Clean up unreachable or orphaned git objects with git prune

Clean up unreachable or orphaned git objects with git prune

Unreachable objects are those that are not accessible by any refs. As an example, say we have made two commits, and reset them to different heads by calling git reset <commit_id> command. Though the git log command will not show the commit info, git still stores it internally as a dangling object.

Find the dangling commit

git fsck --lost-found

Expire all the entries that older than now

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

Check the change

git prune --dry-run --verbose --progress --expire=now

Running prune

git prune --verbose --progress --expire=now

Check for the dangling commits

git fsck --lost-found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment