Git - compress .git directory

8 points
Created by:

In this short article, we want to show how to remove unnecessary files and compress required files in a better way in the .git directory.

Quick solution (run the following command in your project directory):

git gc --prune=now

Example output:

Enumerating objects: 1210, done.
Counting objects: 100% (1210/1210), done.
Delta compression using up to 24 threads
Compressing objects: 100% (1054/1054), done.
Writing objects: 100% (1210/1210), done.
Total 1210 (delta 253), reused 0 (delta 0), pack-reused 0

Note: the above operation reduced .git directory size for the presented output from 2.61GB to 0.98GB.


From Git Documentation:


Prune loose objects older than date (default is 2 weeks ago, overridable by the config variable gc.pruneExpire). --prune=now prunes loose objects regardless of their age and increases the risk of corruption if another process is writing to the repository concurrently; see "NOTES" below. --prune is on by default.


  1. git-gc (--prune=<date>) - Git Documentation
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂