Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout a single file from another branch and put in different folder

Tags:

git

I am trying to git checkout a single file from another branch.

Everything is fine, but it puts the file in the same directory tree of the branch that I am checking out.

There is a way to specify a different destination folder during git checkout?

This is what I did:

git checkout other_branch -- path/to/file/xxx

git status:

new file:             path/to/file/xxx

this the result I need (put xxx into the root directory of my working branch):

new file:             ./xxx
like image 405
fromthestone Avatar asked Apr 01 '19 10:04

fromthestone


1 Answers

You have 2 options

  1. chain 2 commands, git checkout other_branch -- file.txt && git mv file.txt folder/file.txt
  2. or you can use worktree
like image 86
Avi Fatal Avatar answered Sep 17 '22 15:09

Avi Fatal