Search code examples
gitunixmergecherry-pickgit-cherry-pick

How cherry-pick from one branch to another branch without checkout on this branch


I have 3 branches. dev, master, master_copy. Now I am on the master branch and a need cherry-pick commit from dev branch to master_copy WITHOUT checkout to master_copy or dev branch. How I can do this?

I need like this cherry-pick <hash> dev master_copy


Solution

  • If you do not want to checkout something else consider using a worktree for that:

    git worktree add blah master_copy
    cd blah
    git cherry-pick some-commit
    cd ..
    git worktree remove blah
    

    It's an overkill but at least will allow you to cherry-pick without moving on the default working tree.