How to get all the files from one git branch, and put them into the current branch without merging

git

I don't want to commit anything. I just want to take all the files from a different branch and replace all the current files I'm working on with those, while it doesn't change my current branch at all, essentially like a merge, but without creating that merge state.

The end result would be the same as checking out a different branch, copying the files, then going back to original branch, and just pasting on top of them.

EDIT:
I tried merging the branch into the working tree so it was in the merge state, then doing a git reset originalbranch, and that nearly worked, but it left all the conflicted files with the diff comments…

EDIT2:
Just realized I was on SU and not SO…

Best Answer

This seems to do the trick:

git merge otherbranch --no-commit --no-ff -X theirs
git reset currentbranch

"-X theirs" is needed since "--strategy=theirs" isn't a valid strategy.

"--no-commit --no-ff" prevents the merge from going through just leaving the files in the working tree

And the reset cancels the merge state, but leaves the files.

Related Question