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?
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 -- .
git stash
, run Anish's suggested command, then git stash pop
?
Have a look at git worktree.
With git worktree add <checkout_path> <otherBranch>
you can checkout the given branch to the given path.
Create additional clone of used local repo and checkout/merge in it. It will be really The Easiest Way (tm)
git diff --name-status HEAD <otherBranch> | grep -e "^A" | cut -f 2 | xargs git checkout <otherBranch> --
Does the job.