January 5, 2023
What the -u Flag in Git Does
Justin Golden
Length: Short
Level: ✓ Beginner ✓ Intermediate X Advanced
Intro
You may have seen the -u
flag when reading about git online, such as in git push -u origin master
.
The Docs
The -u
flag is the same as --set-upstream
, which in the git push docs says:
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull and other commands.
Explanation
When you push to your local branch with -u
, your local branch will be linked to the remote branch.
Specifically, it sets the origin as the upstream remote in your git config.
Result
This means you can use git pull
and git push
without having to specify arguments each time.
More
You can always run git push --help
to read the docs on the command line, and offline : )
More Blog Articles