Remove Orphaned Commits From History

I deleted a branch that was accidentally pushed to my bitbucket repo. After deleting the branches using `git push origin --delete BRANCH_NAME`, commits from the branch still show up in the BitBucket web UI under the commit history for "all branches". I would like to clean up the history so that these commits, which are no longer part of any branch, are not displayed.

The commits no longer appear to be part of the git repository (e.g. if I try to use `git show COMMIT_HASH` I get a "bad object" error, indicating no commit exists with that hash, yet these commits still show up in the Web UI)

Is this possible to purge these commits such that they no longer appear in BitBucket?

2 answers

Try running garbage collector 

git gc --aggressive --prune=now


This does not appear to be a problem in my local git repository, it only appears to be a problem in the BitBucket web UI. How would I push removal of commits to the origin repo?

The branch wasn't showing up when I pulled the repo locally, but when I used "git ls-remote" I was able to see the remote branch and delete it.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,940 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you