If you want to keep the upstream repository with full history, but local smaller checkouts, do a shallow clone with git clone --depth=1 [repo]
.
After pushing a commit, you can do
git fetch --depth=1
to prune the old commits. This makes the old commits and their objects unreachable.git reflog expire --expire-unreachable=now --all
. To expire all old commits and their objectsgit gc --aggressive --prune=all
to remove the old objectsSee also How to remove local git history after a commit?.
Note that you cannot push this "shallow" repository to somewhere else: "shallow update not allowed". See Remote rejected (shallow update not allowed) after changing Git remote URL. If you want to to that, you have to stick with grafting.