git cherry-pick to another branch
Crazy idea (based on mnaoumov's comment) if you really want to avoid touching the checked out files (say you don't want to disturb your build system) … that's what I want anyway.
- Clone the whole git repo to a temporary directory.
- Do the work in the clone.
- Add the clone as a remote.
git fetch clone && git branch mybranch clone/mybranch -f
- Clean up.
This would be a thing to automate. If you have filesystem snapshots, cloning the whole repo is cheap – perhaps not so crazy after all…
https://github.com/lennartcl/gitl provides "git cherry-copy" and "git cherry-move" scripts that do this and handle most of the corner cases.
That's not possible - simply imagine what would happen if there was a conflict that couldn't be resolved automatically. For the same reason you also can't update branches that are not currently checked-out (even if a fast-forward was possible).