I have a script that generates a lot of commits to a git repository, then periodically pushes all branches. There is no need to keep a big history on that machine and it eats up disk space pretty quickly (and my disk space is scarce).
I am currently running a periodic
git commit -a (...)
git push --all
git prune
git gc
which is not sufficient to keep disk usage low enough on the long run. I am looking for a command to add to this script that would keep only the last few commits from each branch (I only have 2) on this machine and then let git gc
reclaim disk space for me.
Let me clarify: I do not want to rewrite history, just to keep the local repository .git
directory as small as can be, while keeping the full history on origin
. Surprisingly I found very little information on that.
EDIT: this sounds much like a shallow repository (which I never used), but from what I read here, a shallow repository means only to skip part of the history at cloning time, not forgetting data after commit/push.
There is a possible workaround, which I will use if nothing better arises:
# recreate a shallow clone every commit
git commit -a && git push
rm -rf .git/
git clone --depth=1 # shallow clone