David David - 5 months ago 27
Git Question

Git GC followed by Git Push says "Everything is up to date"

I have a Git repository that got some Blobs checked in. Ive purged them and cleaned history. That all appears to have gone ok.

Now if I do a

git checkout master

I get a 200 MB download

git count-objects -v

shows in-pack: 21409

git gc --aggressive --prune=now

followed by

git count-objects -v

shows in-pack: 15976

However heres where I get in trouble.

git push origin --force --tags

gives me
Everything up-to-date

git status

gives me

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

and if I clone the repo again at this point I start over with the 21409
How do I Push the git gc up to master so it comes down clean every time?


You cannot push garbage collected data to a server. You need to run

git gc

on the server. Alternatively wait a week or two until the server automatically invokes garbage collection.

And it makes sense that trying to push cleaned up data does come back with everything up to date: Garbage collection does not change your repo content, it only removes unneeded data (not in branches or tags) and compresses redundant data (without changing any actual data).

Pushing a branch means pushing all the data that is required for this branch. All the unneeded stuff that gc might have removed is not part of any branch, so Git does not even try to push it.

Also the branch on your machine and the server are the same, it is just in a different representation. There is no need to upload it again.

Git does not delete commits if you delete them from history. It merely disconnects them from the graph. Git then (both servers and clients) periodically runs gc, removing unneeded commits and repacking needed ones.