Git cherry pick

  • |
  • 27 September 2023
  • git cherry-pick is useful command to pick specific commit or multiple commits from another branch and merge it to another branch(or we can say that your current branch)
  • This command is useful when you want you to do undoing changes.

Usage:

$ git cherry-pick <commitHash> <commitHash>

# example
$ git cherry-pick 2fa245 2ba5gvd
  • git cherry-pick could be useful for the following scenario:

For instance, as a frontend developer, you need to do some test with specific endpoint from your backend service. However, let’s assume that specific endpoint has not been added to master branch of the repo. To be able finish your test, you can (temporarly) add the commit(which includes endpoint implementation) into your current frontend-branch using cherry-pick. After you test the endpoint you may remove it. (or create new branch with includes the specific commit, using cherry-pick, then delete the branch, that’s much better)

Let’s do an example. Here is the current branch info: (assume that this is a mono repo - one repo includes both backend and frontend -)

/git/cherry_pick/branches.png

To be able test the endpoint you can run the following commands:

$ git checkout frontend-branch
$ git cherry-pick f

After these commands here is the frontend-branch:

/git/cherry_pick/after_cherry_pick.png

You May Also Like

Git Interview Questions
  • 21 Sep, 2023

Git Interview Questions

Git is a tool for keeping track of changes in computer programs. It&rsquo;s free to use and lots of people in the software field use it. Now, …

Using Git Professionally
  • 19 Sep, 2023

Using Git Professionally

In this long blog, we are going to improve our git knowledge. I will try to explain the some concepts behing the basic things in git. Writing perfect …