by BehindJava

What is Git cherry pick

Home » interview » What is Git cherry pick

In this tutorial, we are going to learn about Git cherry pick in detail.

Git cherry pick

This is used to selectively pick only a few commits and bring them to the master branch.

  1. Create a commit on master.

    touch f1
    git add .
    git commit -m "a"
  2. Create a test branch and create few commits on it.

    touch f2
    git add .
    git commit -m "b"
    touch f3
    git add .
    git commit -m "c"
    touch f4
    git add .
    git commit -m "d"
    touch f5
    git add .nf
    git commit -m "e"
  3. Check the commit history.

    git log --oneline
  4. To checkrry pick only c and e commits to master.

    git checkout master
    git cherry-pick c_commitid e_commitid