Search code examples
gitgit-push

Is there any difference between "-u" and "--set-upstream" for the "git push" command?


Can someone please explain the difference, if it exists, between both commands:

  1. git push --set-upstream origin master
  2. git push -u origin master

I tested both and both push but I am unable to see the difference between them.


Solution

  • Those are the exact same command. -u and --set-upstream are different names for the same flag.

    Quoting the docs for git push:

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

    Do note that setting an upstream for the master branch is entirely optional. You can omit -u/--set-upstream entirely if you don't plan on using the argument-less variants of git push/git pull/etc. See What is a git upstream and Definition of "downstream" and "upstream" for more information on what setting an "upstream" means in git.