Checkout all files from branch, without changing HEAD nor existing files

What is the best way to checkout/merge all files from a branch into the working directory, that currently do not exist there, but without changing the repository state, HEAD, or existing files?

Is this possible with a one line command?


Solution 1:

git checkout can take paths as an argument, which, if given, leaves HEAD alone, and just checks out those paths into your working directory and index, so you can just use:

git checkout branchname -- .