Getting Git

A comprehensive video course from git init to Git Master.

init: git cherry-pick


In this video we'll learn how to use git cherry-pick.

We've seen how to merge branches together as well as adjust the commit history of a branch.

There will be times when you make changes on another branch and may not want to merge all of the commits and it's more work to rebase.

For example, maybe you just want to get one specific commit from the branch.

In these cases, you can use git cherry-pick.

Let's demonstrate this by finding a commit from another branch that we want to use.

So I'll run git log and pass it the working-quickly of a branch. This shows me the commit history for working-quickly.

Let's copy the SHA for the second commit.

From the branch I want to add the commit to, in this case the master branch, I'll run:

git cherry-pick SHA

We see Git adds this commit and we can run git log to verify it has been added to the master branch.

But notice the commit SHA has changed. This is important because Git uses SHAs as a unique identifier.

Since the identifier is different, Git will see these two commits as different even though they contain the same changes.

We'll learn this more in one of the Everyday Git videos. For now, use git cherry-pick when you don't intend to merge the whole branch.