what is use of -u flag while pushing commits to some git repo? I mean what is differnece between git push origin master
and git push -u origin master
? Can anyone please describe its usage ?
Asked
Active
Viewed 1.2k times
40

Hardik Joshi
- 839
- 2
- 8
- 14
-
possible duplicate of [What exactly does the "u" do? "git push -u origin master" vs "git push origin master"](http://stackoverflow.com/questions/5697750/what-exactly-does-the-u-do-git-push-u-origin-master-vs-git-push-origin-ma) – Kyle Trauberman Jul 31 '12 at 18:58
-
@KyleTrauberman it is indeed. Would you mind voting to close it. – Matti Lyra Nov 09 '12 at 10:19
-
Does this answer your question? [What exactly does the "u" do? "git push -u origin master" vs "git push origin master"](https://stackoverflow.com/questions/5697750/what-exactly-does-the-u-do-git-push-u-origin-master-vs-git-push-origin-ma) – Uri Meirav Mar 04 '21 at 09:26
1 Answers
36
The git(1) manual page says:
-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..merge in git-config(1).
Basically, you use this flag when you want to set origin as the upstream remote for a branch. This is needed if you don't want to manually specify the remote every time you use git pull
.
See Also
http://git-scm.com/book/en/Git-Branching-Remote-Branches#Tracking-Branches

Todd A. Jacobs
- 81,402
- 15
- 141
- 199
-
13Thanks for explaining the documentation. Gotta love git's docs for its clearness (sarcasm). – sargas May 22 '14 at 14:49