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
.
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.