How to cherry-pick the last sha from another branch in Git with 1 command?

GitGit BranchShaGit Cherry-Pick

Git Problem Overview


I find myself doing this a lot when cherry-picking a commit from another branch.

$ git log -1 another_branch
commit <commit_sha>
// copy <commit_sha>
$ git cherry-pick <commit_sha>

Can I do all of this in one command, if so, what is it?

Git Solutions


Solution 1 - Git

Just go with:

$ git cherry-pick another_branch

This will cherry-pick the last commit from another_branch.

Branches in git are just references to the last commit in that branch, you can use them instead of commit SHAs in your commands.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFoxyGioView Question on Stackoverflow
Solution 1 - GitpbetkierView Answer on Stackoverflow