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.

Cancel
9
  • 30
    As noted below, for an existing branch, you can use git push -u origin branch-name.
    – Zags
    Mar 6, 2014 at 23:46
  • 6
    If local branch is current branch, and local branch is not already tracking a remote, git pull will often provide helpful messages about the appropriate command to set tracking information Aug 7, 2015 at 12:59
  • 85
    It's annoying when one is learning git to be shown a link to the git documentation. That documentation appears to be written for people that already know what they are doing with git. Mar 18, 2017 at 13:39
  • 12
    as of Git 2.10 you should first checkout to intended local branch and then do this git branch --set-upstream-to origin/<branch> Sep 18, 2017 at 4:59
  • 4
    --set-upstream produces an error: fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead. so git branch --set-upstream-to origin/<branch name> is the current command that works.
    – Super Jade
    Aug 24, 2018 at 17:47