Mastering GitHub Cherry-Pick: Apply Specific Commits to Your Branch

Anil R
1 min readDec 10, 2024

--

In GitHub, cherry-pick is a command that allows you to apply a specific commit from one branch into another branch. It is used when you want to bring in a commit that might not be part of a branch’s normal history (for example, a bug fix or a small feature), without merging the entire branch.

How it works:

  1. Identify the commit: First, you identify the commit hash (a long alphanumeric string) that you want to cherry-pick.
  2. Run the cherry-pick command: You use the git cherry-pick <commit-hash> command in the branch where you want to apply the commit.
  3. Resolve conflicts (if any): If there are conflicts between the commit being applied and the current state of the branch, you’ll need to resolve them manually.
  4. Commit the changes: Once the conflict is resolved (if needed), the commit will be applied to your current branch, and you can push the changes.

Example:

  1. Switch to the target branch:
git checkout target-branch

2. Cherry-pick the commit:

git cherry-pick <commit-hash>

This is useful in situations where you need a specific change from a feature branch but don’t want to merge the entire branch, keeping your history cleaner and more focused.

--

--

Anil R
Anil R

Written by Anil R

Full Stack Developer with 15 years experience.

No responses yet