How do I remove sensitive/unwanted content that was pushed to my Bitbucket Data Center instance?
Purpose
The purpose of this article is to describe the steps that can be taken to remove sensitive or otherwise unwanted information that has been pushed to a repository hosted in Bitbucket Data Center.
Background
When a sensitive file or line has been pushed to a git repository, such as an SSH key or password, if your team has added additional commits since this content was added - simply deleting the content in the latest commit is not enough, as this information is still going to exist within the commit history for this repository.
As soon as this sensitive commit has been pushed, your team should treat this data as though it were compromised. Any passwords or SSH keys should be immediately changed, as it's possible that the sensitive information has been already manually copied. In addition, any clones or forks that contain this commit will not be affected by these steps.
What's more, rewriting history and force pushes can lead to undesirable results and unexpected behaviours in Bitbucket Data Center, which is why we generally discourage this practice if you can avoid it at all.
Solution
There are two different methods you can use to remove this sensitive content from your repository's commit history:
- The git command
git filter-branch
- BFG Repo-Cleaner
Both methods ultimately will end up re-writing the history of the repository to make it as though the sensitive commit was never pushed in the first place.
The BFG Repo-Cleaner is a third-party utility and is therefore outside of the Atlassian Support Offerings. Any issues arising from the usage of this utility will not be supported by Atlassian.