Last active
February 21, 2025 17:21
-
-
Save giorgichi/7e3d9cfd725ed1855f43e869d501e896 to your computer and use it in GitHub Desktop.
Clean Git History
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reduce Repository Size | |
This document describes how to remove old files from Git history to reduce repository size | |
To remove sensative info (like passwords) follow this [document](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository). | |
Check size of the repo by running | |
`git count-objects -vH` | |
Install **git-filter-repo** from https://github.com/newren/git-filter-repo/tree/main | |
``` | |
python3 -m pip install --user git-filter-repo | |
git --exect-path | |
``` | |
Run analysis of the repository | |
``` | |
git filter-repo --analyze | |
``` | |
If it does not run you will need to [download the file](https://github.com/newren/git-filter-repo/blob/main/git-filter-repo) and mannually add to git path (which can be found by `git --exec-path`) | |
After runing the `filter-repo --analyze`, you can go and check deleted files by navigating to `head -20 .git/filter-repo/analysis/path-deleted-sizes.txt` | |
To remove files and folders from the repository | |
`git filter-repo --invert-paths --path directory/file_name --force` | |
To delete completly and emptry repositrory size | |
`git reflog expire --expire=now --all && git gc --prune=now --aggressive` | |
Update remote repositroy by forced pushing the changes | |
`git push --force` | |
OR | |
`git push --force --mirror` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment