Reputation: 5531
I have two branches.
Now, in my machine, I have only checked out branch-B. I need a folder from origin/branch-A without creating a branch in my current repo (actually I am doing an automation)
I tried these.
Try 1:
branch-B $ git restore --source branch-A folder-x
Problem:
It gives error as I haven't created a branch (branch-A) in my local
Try 2:
branch-B $ git fetch `git remote show` && git checkout `git remote show`/branch-B folder-x
This works, but always trying to get all files (from first).
As in my second try, it is always trying to get all files (may be some reset to HEAD of branch-B ).
Is there any way to do update alone for that folder?
Upvotes: 1
Views: 3470
Reputation: 3251
You can use the checkout command,
git checkout <remote-name>/<branch-name> -- <pathspec>
Suppose, in branch-A
you have folder-x
sitting directly under the root and this folder-x
hosts file-x.txt
, then the command to pull in just the file-x.txt
from branch-A
of the remote origin
would be,
First perform a fetch,
git fetch
,
Then checkout the file,
git checkout origin/branch-A -- folder-x/file-x.txt
If you want to checkout the whole directory,
git checkout origin/branch-A -- folder-x
Upvotes: 2