Git: copy all files in a directory from another branch Git: copy all files in a directory from another branch git git

Git: copy all files in a directory from another branch


As you are not trying to move the files around in the tree, you should be able to just checkout the directory:

git checkout master -- dirname


If there are no spaces in paths, and you are interested, like I was, in files of specific extension only, you can use

git checkout otherBranch -- $(git ls-tree --name-only -r otherBranch | egrep '*.java')


To copy the directory without tracking it:

git restore --source master dirname