Skip to content

Instantly share code, notes, and snippets.

@jkeefe
Last active December 24, 2024 17:02
Show Gist options
  • Save jkeefe/0d3c21f0cb0c9a432536be9c39e39008 to your computer and use it in GitHub Desktop.
Save jkeefe/0d3c21f0cb0c9a432536be9c39e39008 to your computer and use it in GitHub Desktop.
Removing large files from Github repo commit history
# example: get rid of large `.tif` and `.nc` files in gis/tmp
# from https://www.geeksforgeeks.org/how-to-remove-a-large-file-from-commit-history-in-git/
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch gis/tmp/*.tif' \
--prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch gis/tmp/*.nc' \
--prune-empty --tag-name-filter cat -- --all
git push origin --force --all
# Caveat: Force pushing rewrites history on the remote server, which can disrupt other
# developers who have already pulled that branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment