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?
CodePudding user response:
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