When you’re working on multiple branches in Git, there are times when you only need to copy a specific commit from one branch to another — not the whole branch. Maybe you fixed a bug in one place and want that same fix elsewhere. Maybe you pushed a small feature but realised it belongs on a different branch.
So, how do you add a single commit from one branch into another without merging the entire history?
The answer: Git cherry-pick.
What you will learn?
In this guide, I’ll show you exactly how to:
- Add a commit from one branch to another
- Avoid unnecessary merges
- Keep your Git history clean
- And do it all confidently, even if you’re just starting out!
What Does It Mean to Add a Commit from One Branch to Another?
Let’s say you made a change on one branch and later realized that the same change is needed on another branch too. Instead of rewriting the same code or merging the full branch (which might bring in unrelated changes), you can cherry-pick just that one commit.
This is perfect when:
- You want to apply a patch to multiple versions or environments.
- You want to reuse a fix from another branch.
- You accidentally committed something to the wrong branch.
Copy a Commit Between Branches in Git
Switch to the Destination Branch
This is the branch where you want the commit to be added:
git checkout your-target-branch
Replace your-target-branch
with the actual destination branch name.
Find the Commit You Want to Add
Use the Git log to locate the commit from the source branch:
git log your-source-branch
Find the commit hash for the change you want to bring over.
Example output:
commit a1b2c3d4
Author: Jigar Karangiya
Date: Tue May 28 2025
Fix: Improve shipping method logic for multi-step checkout
Copy the commit hash (like a1b2c3d4
).
Add That Commit to the Current Branch Using Cherry-Pick
Now run:
git cherry-pick a1b2c3d4
This applies the selected commit to your current branch as a new commit, keeping its original changes.
Handle Merge Conflicts (If Any)
If Git detects conflicts during the cherry-pick process:
- Manually resolve the conflicts in your files.
- Stage the resolved files:
git add .
3. Continue the cherry-pick:
git cherry-pick --continue
Push the Updated Branch
Once the commit is added, push your changes:
git push origin your-target-branch
Extra Tip: Adding Multiple Commits
To copy multiple commits (a range) from one branch to another:
git cherry-pick <start-commit>^..<end-commit>
Conclusion
Cherry-picking is one of those Git superpowers that developers often overlook. It’s the perfect tool when you want surgical precision in managing your Git history.
Now that you know how to cherry-pick a single commit from one branch to another, you’ll save time, avoid messy merges, and write cleaner Git logs — all while looking like a pro!
You may also like,
Leave a Comment