I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?
I know I can just edit the
I do this as a side-effect of pushing with the -u
option as in
$ git push -u origin branch-name
The equivalent long option is --set-upstream
.
The git-branch
command also understands --set-upstream
, but its use can be confusing. Version 1.8.0 modifies the interface.
git branch --set-upstream
is deprecated and may be removed in a relatively distant future.git branch [-u|--set-upstream-to]
has been introduced with a saner order of arguments.…
It was tempting to say
git branch --set-upstream origin/master
, but that tells Git to arrange the local branch "origin/master" to integrate with the currently checked out branch, which is highly unlikely what the user meant. The option is deprecated; use the new--set-upstream-to
(with a short-and-sweet-u
) option instead.
Say you have a local foo
branch and want it to treat the branch by the same name as its upstream. Make this happen with
$ git branch foo
$ git branch --set-upstream-to=origin/foo
or just
$ git branch --set-upstream-to=origin/foo foo