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 .git/config
file, but it seems there should be an easier way.
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 |
||||
Given a branch As of Git 1.8.0:
Or, if local branch
Or, if you like to type longer commands, these are equivalent to the above two:
As of Git 1.7.0:
Notes: All of the above commands will cause local branch See also: Git: Why do I need to do `--set-upstream` all the time? |
|||||||||||||||||||||
|
Another option is not to use the command line at all. Git GUI clients such as SourceTree take away much of the syntactical learning curve that causes questions such as this one to be amongst the most viewed on StackOverflow. In SourceTree, simply right click on the local branch, select "Track remote branch >" and pick from the list. |
|||||||||
|
You might find the
|
|||||||||||||
|
I believe that in as early as Git 1.5.x you could make a local branch Given that
This recreates Note, if
Followed by the previous command to promote the local branch into a tracking branch. |
|||||||||
|
Actually for the accepted answer to work:
|
|||||||||
|
In very short
This will make your |
|||||||||
|
For 1.6.x, it can be done using the git_remote_branch tool:
That will cause Git to make |
||||
|
You can do the following (assuming you are checked out on master and want to push to a remote branch master): Set up the 'remote' if you don't have it already
Now configure master to know to track:
And push:
|
|||||||||||||||||
|
I do this as a side-effect of pushing with the
The equivalent long option is The
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
or just
|
|||
|
Make sure you run :
to be able to push trouble free |
|||||
|
Editing If you don't want to muck with the file by hand (and it's not that hard to do), you can always use There are, of course, ways to automatically track a remote branch when using |
|||
|
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?
git push -u origin branch-name
. – Zags Mar 6 '14 at 23:46git branch
documentation. – Cupcake May 23 '14 at 18:26