Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predict how much data will be pushed in a git push

I am occasionally on an expensive Internet connection and I would like to know (at least approximately) how much data will be pushed to the remote in a git push.

like image 553
gak Avatar asked Nov 14 '10 21:11

gak


People also ask

How much time does git push take?

1.1 . After a reset git push and all other git-origin-accessing commands go down from 1 minute to a few seconds.

How does git push know where to push?

git has a system of remotes which allows to specify URLs and transports to repositories other than the one where you're working. git push origin master pushes the current branch to the remote called origin as the branch master. You have a remote called origin.

Does git push do a fetch?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.


1 Answers

Actually, I think I like my comment enough to post it as an answer!

When you push, git creates a pack of all the necessary objects and uploads that to the remote. This means we're looking for a way to predict that pack size. Since the packs are compressed, that makes it very difficult to do anything based on diffs or object sizes; what we really want to do is just see how big that pack will be. It'd be nice if you could interrupt the push, just after it's constructed the pack, and decide to proceed based on the pack size, but I don't think that's possible. My best guess is to try to recreate the pack that would be pushed and inspect that.

A bundle file is basically a pack with header information (have a look at the source if you like). This means it's a convenient porcelain command that'll create a file with the size you care about. (Much easier than trying to use pack-objects manually.) Use something like this:

git bundle create foo.bundle ^origin/master master 

That'll give you a bundle containing everything needed to get to master, given that the remote has origin/master - exactly the same thing that should be pushed by git push origin master. If you have additional branches you'll be pushing, you can tack them on as well; it's just taking rev-list args:

git bundle create foo.bundle ^origin/master master ^origin/topic topic ... 

Just check the size of that created bundle; it should be nearly equivalent to what you'll end up pushing. This does mean that you'll end up having to create the pack twice (once with the bundle and once with the push), but unless this is a really big push which takes a long time to pack up, that shouldn't be a huge problem.

like image 53
Cascabel Avatar answered Sep 22 '22 17:09

Cascabel