OMG this is insane (but it does work).
To delete a large file from a Git repository after it has been added, you can follow these steps:
Make sure you have committed any pending changes before proceeding.
Identify the file you want to remove. Take note of its name and path.
Open the terminal or command prompt and navigate to your Git repository directory.
Use the git filter-branch
command to remove the file from the entire commit history. Replace FILENAME
with the actual name and path of the file:
git filter-branch --tree-filter 'rm -rf FILENAME' -- --all
This command will rewrite the commit history and remove the file from all branches and tags.
Note: Be cautious when performing this operation as it modifies the commit history permanently. It is advisable to make a backup of your repository before proceeding.
Once the command completes successfully, the file will be removed from the Git repository.
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now
These commands remove the references to the original commits and clean up any unused objects.
git push origin --force --all
Note: Remember, force-pushing modifies the remote repository’s commit history, so be cautious when using this command.
After following these steps, the large file should be deleted from your Git repository.