My current base has a total size of approx. 200MB.
But my .git folder has an amazing size of 5GB (!). Since I push my work to an external server, i don\'t need any b
Shrink a Git Repository by removing some files log history from the
.git
Folder based on their last updated time.
I had faced the same issue on my Local Machine. The reason was I have deleted some massive files from my local and committed to Central Repository. But event after git status
, git fetch
and git pull
. My .git
folder size is about 3GB. later I ran the following command to reduce the size of the .git
folder by considering the files which have changed/expired a month ago.
Command
$ git remote prune origin && git repack && git prune-packed && git reflog expire --expire=1.month.ago && git gc --aggressive
Git Commands and their short description:
git-prune
- Prune all unreachable objects from the object database.git
directory. git reflog directories can be found at .git/logs/refs/heads/.
, .git/logs/HEAD
, and also .git/logs/refs/stash
if the git stash has been used on the repo. git reflog at a high level on the Rewriting History Page.
git reflog expire --expire=now --expire-unreachable=now --all
git gc
handles and git prune
should not be used standalone.git gc --aggressive
: git-gc - Cleanup unnecessary files and optimize the local repository.git prune, git repack, git pack and git rerere
. The high-level responsibility of these commands is to identify any Git objects that are outside the threshold levels set from the git gc
configuration. Once identified, these objects are then compressed, or pruned accordingly.Commonad with Outcome:
$ git remote prune origin && git repack && git prune-packed && git reflog expire --expire=1.month.ago && git gc --aggressive
Enumerating objects: 535, done.
Counting objects: 100% (340/340), done.
Delta compression using up to 2 threads
Compressing objects: 100% (263/263), done.
Writing objects: 100% (340/340), done.
Total 340 (delta 104), reused 0 (delta 0)
Enumerating objects: 904, done.
Counting objects: 100% (904/904), done.
Delta compression using up to 2 threads
Compressing objects: 100% (771/771), done.
Writing objects: 100% (904/904), done.
Total 904 (delta 343), reused 561 (delta 0)