1

I often find myself doing git push and sometimes git push -u origin master. I would like to know which one executes faster. Since git push uses the default repository which I am working on and the later one explicitly defines the repository to push on. So, I am bit confused here and would like fellow developers to have their say. So that I can use the right code at right time.

Please do not link me to following sites.

I have been many times there.

Community
  • 1
  • 1
Samundra
  • 1,869
  • 17
  • 28
  • Did you try it yourself? – devnull Aug 08 '13 at 05:45
  • Yeah ! I have tried them myself, but they both seem taking around 2-4 secs for push using ssh for me when I am just pushing a single file, which should have been a matter of second. – Samundra Aug 08 '13 at 05:50
  • Speed depends upon the amount of changes made. Also ssh authorisation may take-up a chunk of those 2-4seconds. – TheCodeArtist Aug 08 '13 at 05:53
  • Ok. So, is there anything that we can do to speed up pushing besides compressions which git does by default. I was thinking like assigning more memories etc like that in java vm. I don't know if that can be done with git or not, just curious. – Samundra Aug 08 '13 at 05:56
  • 2
    You only need to `push -u` *once*: see http://stackoverflow.com/a/17096880/6309. After the initial `push -u`, `git push` is enough. – VonC Aug 08 '13 at 06:22
  • On your development machine, what is the output of `$ GIT_TRACE=1 git push` ? – TheCodeArtist Aug 08 '13 at 07:16

2 Answers2

4

They both execute at the exact same speed remotely. Take a look at the man page entry for the -u parameter:

   -u, --set-upstream
       For every branch that is up to date or successfully pushed, add upstream
       (tracking) reference, used by argument-less git-pull(1) and other 
       commands. For more information, see branch.<name>.merge in git-config(1).

All that means is that after you successfully push, in the local .git/ folder, you update your config to track any remote branches. So that means, -u is only slower because it has to do some extra file I/O on your local machine to update tracking info. It's not likely a noticeable difference unless you're doing something really crazy.

Swift
  • 13,118
  • 5
  • 56
  • 80
  • 1
    There's another difference though, because `git push origin master` (with or without `-u`) specifies that only branch `master` should be pushed. Now that there's a `push.default` you can choose how push-with-no-extra-arguments works, but the "default default" is "matching" which might push additional branches. – torek Aug 08 '13 at 08:33
3

It's going to depend a lot on your setting of push.default. Also, If git push works then -u must be redundant.

If your not pushing any more objects in the first case, the difference in performance is likely to be negligible.

If the file being pushed is not very large then what you are seeing is most likely to be the overhead of setting up an ssh session on the particular host on question or possibly a very slow hook being run on the remote end.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • I'm not sure this is correct. I think `-u` just has to do with updating the local tracking info, no? – Swift Aug 08 '13 at 06:03
  • @Swift: exactly, so with `push.default` in most standard settings, if `push` works it means that tracking information is likely to be set up for the current branch an another `-u` is probably redundant. – CB Bailey Aug 08 '13 at 06:05