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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityWhat 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 -- .
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.
Have a look at git worktree.
With git worktree add <checkout_path> <otherBranch>
you can checkout the given branch to the given path.