1

I am trying to checkout a single file from a remote branch but am having trouble with the proper syntax. If this file was on master, I could run (link):

$ git checkout origin/master -- path/to/file

but if I run a similar command with my branch name I get:

$ git checkout origin/my-branch-name -- path/to-file
fatal: invalid reference: origin/my-branch-name

What is the equivalent command to check out this single file on a remote branch?

Steven Hepting
  • 12,146
  • 8
  • 39
  • 48

1 Answers1

1

In the linked question origin/master is not a remote branch — it's local remote-tracking branch. If you don't have the branch locally you need to fetch it first:

git fetch origin
git branch -r # list local remote-tracking branches
git checkout origin/my-branch-name -- path/to-file
phd
  • 69,888
  • 11
  • 97
  • 133