rtyley / bfg-repo-cleaner

Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala
https://rtyley.github.io/bfg-repo-cleaner/
GNU General Public License v3.0
11.1k stars 549 forks source link

How to Remove a File from GitHub Repo and History, Including Pull Requests? #520

Open genieai-vikas opened 1 month ago

genieai-vikas commented 1 month ago

I want to remove a sensitive file mongodb.key from my GitHub repository, including its history. I followed these steps:

git clone --mirror https://github.com/test-co/github-action-poc
bfg --delete-files mongodb.key github-action-poc.git
cd github-action-poc.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force

However, when I try to push, I’m encountering the following errors:

 ! [remote rejected]     refs/pull/7/head -> refs/pull/7/head (deny updating a hidden ref)
 ! [remote rejected]     refs/pull/8/head -> refs/pull/8/head (deny updating a hidden ref)
 ! [remote rejected]     refs/pull/9/head -> refs/pull/9/head (deny updating a hidden ref)
error: failed to push some refs to 'https://github.com/test-co/github-action-poc'

It seems the pull request (PR) references are causing issues. How can I remove the mongodb.key file from the repository, including PRs, and successfully push my changes? What is the correct approach for this?

Thanks in advance!

glebsts commented 1 month ago

You can grep this "remote rejected" from github issues and see that technically the valid way is to create a new repo and push mirror clone edited with BFG to this new repo. Github and Bitbucket do have those internal refs and don't want you to change them.