Skip to main content

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.

Required fields*

6
  • 1
    Great answer! Addresses both common use cases. After running git branch -u origin/my-branch I can run git pull to pull down my changes. Commented Dec 2, 2016 at 22:22
  • 6
    "git checkout -b my-branch -t origin/my-branch" this doesn't work if 'origin/my-branch' doesn't exist yet. Commented Nov 16, 2017 at 18:43
  • 1
    You actually can just do git checkout -t origin/my-branch without the -b my-branch, it will just automatically infer my-branch for the local branch name. However, as @Spongman mentioned, this command doesn't work if origin/my-branch doesn't exist first. Commented May 10, 2018 at 23:11
  • 1
    Yes, will work @wisbucky, -t works just fine. Personally though, even two years after I wrote that reply though, I still prefer splitting in two lines with checkout -b and push -u. It is more explicit and no error on checkout -b when I don't have remote - which happens quite often when experimenting :) Commented May 15, 2018 at 7:32
  • 2
    git push -u origin/my-branch fails for me with fatal: 'origin/my-branch' does not appear to be a git repository. This works: git push -u origin my-branch Commented Oct 26, 2018 at 20:29