Reputation:
I'm not sure if I just need to use this once or every time.
Can I do a
git push -u repo branch
and from there just do a
git push repo branch
because it has already been set? Or do I need the -u every time? g Research
https://git-scm.com/docs/git-push/1.6.1.3
What exactly does the "u" do? "git push -u origin master" vs "git push origin master"
Upvotes: 1
Views: 493
Reputation: 1385
Let me try to explain it :)
-u
just a shorthand of --set-upstream
It means for every branch that is up to date or successfully pushed,
add upstream (tracking) reference so that you can just type the command git push your-branch-name
to push without specifying the remote. Otherwise, it doesn't know where you want to push.
git push -u
is same as git push --set-upstream
Once you set up the upstream, the "upstream" configuration will be saved to git-config and you no need to tell Git anymore about the upstream of this branch. So you just need to execute it once.
After that, you may just simply push the branch using git push your-branch
or git push
for the current branch.
Hope this can help!
Upvotes: 1
Reputation: 230481
You don't need to use it at all. You can push branches just fine without it. But if you want to set up the tracking, then just once is enough (when you first push a new branch).
Or you can add tracking later:
git branch --set-upstream-to=<remote>/<branch> <local_branch>
Upvotes: 2