The -u
in git push -u origin main
is a shorthand option for --set-upstream
.
When you use git push -u origin main
for the first time for a local branch, it does two things:
- Pushes your local
main
branch to the remote repository namedorigin
. If amain
branch doesn't exist on the remote yet, Git will create it. - Sets up a tracking connection (upstream) between your local
main
branch and the remoteorigin/main
branch. This means that Git now remembers that your localmain
branch is associated with themain
branch on theorigin
remote.
Why is this tracking connection useful?
Once the upstream is set, you can use simpler Git commands in the future: