207

I was just wondering what does the -u flag mean in this command?

git push -u origin master
today
  • 32,602
  • 8
  • 95
  • 115
user123456
  • 2,287
  • 3
  • 13
  • 10

2 Answers2

198

The -u option does the following: For every branch that is up to date or successfully pushed, add an upstream (tracking) reference, used by argument-less, git-pull and other commands.

So, after pushing your local branch with the -u option, this local branch will be automatically linked with the remote branch, and you can use git pull without any arguments.

Radllaufer
  • 187
  • 1
  • 2
  • 10
Shunya
  • 2,785
  • 2
  • 18
  • 17
  • 4
    "For every branch that is up to date or successfully pushed" - If it was pushed a remote branch is created, right? so why adding an upstream reference? – Ace May 15 '18 at 08:07
  • 4
    You'll be able to use `git pull` and `git push` without argument. – Patrick Nov 20 '19 at 05:26
  • A late reply for @Ace 's comment: Git tends to shy away from defaults because of how many different ways there are to handle upstream and local repos and their interactions. Using `-u` adds the upstream reference by default *for that branch* so that your local copy has a tracking reference to automatically fill the [`` option](https://git-scm.com/docs/git-push#Documentation/git-push.txt-ltrepositorygt). You can see a good way of changing the default behaviour to [auto set tracking branches in this answer here.](https://stackoverflow.com/a/6089415/270213) – Tom 'Blue' Piddock Sep 15 '21 at 08:31
60

It's the same as --set-upstream

It's used to set origin as the upstream remote in your git config.

It may help if you don't want to manually specify the remote every time you run git push.

Also ...

As you're new to stackOverflow, take your time to read What types of questions should I avoid asking? section of the Help because sometimes you can find the answers by simply browsing the documentation.

Community
  • 1
  • 1
Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72