You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Make an existing Git branch track a remote branch?

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.

Answer

Cancel
30
  • 153
    Is "upstream" the name of the remote? i.e. what most would call "origin" by default?
    – Andrew Vit
    Jun 26, 2010 at 6:30
  • 191
    @Andrew: Yes. git branch --set-upstream master origin/master would be equivalent to what is automatically done when you initially clone a repository. Jun 26, 2010 at 10:09
  • 65
    On a related note, adding this to your gitconfig is awesome: "[push] default=tracking" this will make it so that pushes will go the same place that pulls come from :)
    – jpswain
    Dec 5, 2010 at 4:31
  • 64
    I get "fatal: Not a valid object name: 'origin/master'."
    – joachim
    Mar 24, 2011 at 22:07
  • 97
    git push -u origin foo via
    – Cotton
    Sep 21, 2011 at 7:02