Reputation: 28981
There is a question "Git: copy all files in a directory from another branch" which shows how. But it doesn't delete files that are in the current branch, but that are deleted in the other branch.
There are few solutions I usually use:
Delete the directory locally rm -r dir
, then do git checkout otherBranch -- dir
. It works, but is slow for large directories.
git checkout dir
and then git rm $(git diff --name-only otherBranch -- dir)
. It works, but I think there should be a better solution.
Is there an easier way to do it?
Upvotes: 9
Views: 4382
Reputation: 1616
git reset otherBranch -- dir
git clean -df
git checkout .
This should update the contents of dir with those of the same directory on the other branch.
Upvotes: 3