Skip to main content

Command Palette

Search for a command to run...

git cherry pick - Quite an underrated tool !

Updated
4 min read

You know what — I never dug deeply into what Git can do. It solved my everyday pushes, pulls and fetches, so I was content and didn’t treat it like anything special. That changed when I hit a wall.

Let me tell you a scenario:

In our org, we follow the GitFlow type of branching strategy. main is the stable production branch, develop is the staging branch, and feature-* branches are branched off develop for new work. Ideally, once your feature is complete and tested you raise a PR into develop. But what if your feature depends on other work and takes weeks? develop doesn’t wait — it keeps moving forward. Two months later your feature is ready, but develop has many new commits and a fast-forward merge is no longer an option.

Ideally, the most suitable option for this case is to use git rebase , where you simply change your branch's base (from where you branch started out) (I think in this way actually 😊)

or, you use something known as git cherry-pick that allows you to pick cherries (commits) along the way, which you need and apply those on top of the updated branch.

Let's look at how to do this:

  1. At first we branch-out a fresh feature-latest-* branch from the develop.

  2. Make sure your local repo has the latest changes from all relevant branches develop, feature-old, feature-latest - checked out and pulled in atleast once (so that the commit history is there in our local). You can refer this link for doing this quickly - How to 'git pull' without switching branches (git checkout)?

  3. Now, let's quickly look into the commit history of our feature-old branch and note down the commit hashes which we want to apply on top of feature-latest branch. If we want to take a range, we can only note down the start and end commit IDs or else to selectively choose commits we can take it space seperated. You can use this command to look at the history on your terminal git log --oneline <branch-name>

  4. For example, if we had 3 commits change1(ca82a6d), change2(da82a9d), change3(fa82ae6) one after the other and we wish to apply all 3 commits in order on top of our fresh branch.

  5. Let's checkout to our fresh feature branch : git checkout feature-latest

  6. And we run this command : git cherry-pick -x ca82a6d^..fa82ae6 or git cherry-pick ca82a6d da82a9d fa82ae6 . The -x paramter alters the commit message specifying that it's a cherry picked commit and adds the original commit SHA too.

  7. it means pick all commits in this range. ^ means to include the first commit too, otherwise ommitting that would exclude the first commit.

  8. Once we run this command, git would apply all our commits on top of our current branch (feature-latest) one after the another and if it faces a merge conflict, it would pause there.

  9. You have to solve those merge conflicts and then run git cherry-pick --continue . Or just in case, if you wish to abort the changes in this stage you can run git cherry-pick --abort

  10. Once the cherry pick has completed succesfully, you are now ready with the updated feature-latest branch which you can safely merge to develop.

  11. Simply run git push origin feature-latest and then raise a PR.

When you don't want to rebase or fast‑forward, git cherry-pick lets you selectively apply the exact commits you need onto an updated branch without bringing the whole feature history.
Use it judiciously—expect conflicts, use -x to record the original commit details, and prefer rebase/merge when preserving linear history or full context matters.