Copy directory from another branch

The question arises :Git: copy all files to a directory from another branch , which shows how to do this. But it does not delete files that are in the current branch, but deleted from another.

There are several solutions that I usually use:

  • Delete the directory locally rm -r dir, then execute git checkout otherBranch -- dir. It works, but too slow for large directories.

  • Do git checkout dirand then git rm $(git diff --name-only otherBranch -- dir). It works, but I believe that this should be the best solution.

Any easier way to do this?

+4
source share
1 answer
git reset otherBranch -- dir
git clean -df
git checkout .

This should update the contents of the directory with the same folders in another branch.

0
source

All Articles