Git push --set-upstream vs --set-upstream-to
as per this article , is git push --set-upstream
deprecated and git push --set-upstream-to
should be used instead.
But when I checked the git push documentation, I can only find --set-upstream
, but --set-upstream-to
no, where to be found.
Outdated, then --set-upstream
? Should I use --set-upstream
or --set-upstream-to
?
source to share
It mixes git branch
and git push
.
The command git branch
has both --set-upstream
, and --set-upstream-to
the previous ones are deprecated in favor of the latter for the reason already given in Nick's answer .
The command git push
only has -u
aka --set-upstream
, which takes no arguments. This means that if the push succeeds, your local Git should install, as at the beginning of the branch referenced as origin, the remote tracking branch corresponding to the destination branch, you got another Git to install, which in many cases your own Git has just been created in your repository because their Git just created their branch as well. (Ugh!)
That is, suppose you created a branch newbranch
:
$ git checkout -b newbranch
... work, commit, etc
and want to set its upstream to origin/newbranch
. But if you try, it will fail:
$ git branch --set-upstream-to=origin/newbranch
error: the requested upstream branch 'origin/newbranch' does not exist
because it origin/newbranch
doesn't exist yet, because the other Git at origin
doesn't have a named branch newbranch
.
Soon, you are git push
hosting your local one newbranch
in your Git for Git to create newbranch
in its repository. Now that you have them newbranch
, your Git creates yours origin/newbranch
to remember them newbranch
. And now you can use git branch --set-upstream-to
, but it might be nice if it git push
can do it automatically - and that's the option git push --set-upstream
, aka -u
.
It is related to git branch --set-upstream-to
but not the same.
source to share
It depends on your version of git. --set-upstream-to
was introduced in 2012 in the 1.7.12-1.7.13 timeframe. Any version later than this must include it. This is what the commit said:
commit 6183d826ba62ec94ccfcb8f6e3b8d43e3e338703
Author: Carlos MartΓn Nieto <cmn@elego.de>
Date: Mon Aug 20 15:47:38 2012 +0200
branch: introduce --set-upstream-to
The existing --set-uptream option can cause confusion, as it uses the
usual branch convention of assuming a starting point of HEAD if none
is specified, causing
git branch --set-upstream origin/master
to create a new local branch 'origin/master' that tracks the current
branch. As --set-upstream already exists, we can't simply change its
behaviour. To work around this, introduce --set-upstream-to which
accepts a compulsory argument indicating what the new upstream branch
should be and one optinal argument indicating which branch to change,
defaulting to HEAD.
The new options allows us to type
git branch --set-upstream-to origin/master
to set the current branch upstream to be origin master.
I would say that it is not entirely out of date, but it is discouraged. I don't know if this was very recently deprecated, but the fact that the man page git-branch(1)
for git -2.7.5 mentions this without warning about it means that it is still around and is going to stay around. You just have to be careful.
EDIT: sorry, it's deprecated in commit b347d06bf097aca5effd07871adf4d0c8a7c55bd, but they only commit the mention git-branch
, not git-push
.
source to share