Accidentally commited a large file, and it wasn't the most recent commit, so now I have to dig it out of my history (because of GitHub file size limitations) in order to push my commits to GitHub. Meaning I have a local copy of my repo which I need to edit the history of.
BFG seems to be the universally recommended solution to this problem (even GitHub recommends it). So I downloaded BFG and followed the steps (here: https://rtyley.github.io/bfg-repo-cleaner/).
The only obvious alteration to the steps listed there is that I ran git clone --mirror...
pointing to my local git repo, instead of a github url. This is because the history that needs to be changed exists only on my local machine (GitHub wont let me push it, after all).
But because of this alteration, when I get to the last step in the BFG instructions, git push
, it is actually trying to push to my local directory. And apparently this doesn't work.
git push
(ran in the mirror of my local repo that I made per the BFG instructions) fails with the error message "branch is currently checked out".
I have not been able to find any obvious solution, all of the instructions for BFG seem to assume that you will be cloning from a remote server.
The BFG instructions mentioned in the question recommend only running BFG on a mirror of the repo. However I found that the instructions from GitHub (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository) didn't mention anything about creating a mirror repo.
So my solution was simply to ignore the official BFG instructions and do this instead...
bfg --delete-files ...
, git reflog ...
, git push
) directly in the local repo (not the backup) that needed fixingIt worked like a charm, git push
pushed to GitHub with no issues and I did not lose any data.
I'm not a git or BFG expert, so not sure if there are potential dangers with skipping the mirror-clone step, but if the GitHub docs themselves recommend it, I assume its relatively safe (and you always have your backup anyways).