-6

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.

2
  • 1
    stackoverflow.com/a/53410553/7976758 , stackoverflow.com/a/71272544/7976758 , stackoverflow.com/… Commented Nov 5, 2023 at 18:03
  • You can easily check, for any git command, its documentation by typing git help <cmd> in a terminal. For example, the main answer is an excerpt from git help push. This is the goto method to check if a command supports a specific flag, or how it should be worded, or ... Commented Nov 6, 2023 at 5:07

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

There is no difference between ‘git push –set-upstream origin master’ and ‘git push –u origin master’. The ‘-u’ option is a shorthand for ‘—set-upstream’. Both commands will accomplish the task of pushing changes to the remote repository and setting up tracking for the specified branch. The use of -u is just a shorter and more convenient way to specify --set-upstream.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.