Git Cherry Pick - Atlassian Git Tutorial
Git Cherry Pick - Atlassian Git Tutorial
Tutorials
Enter Your Email For Git News
Learn Git
Beginner
Team collaboration.
Often times a team will find individual members
working in or around the same code. Maybe a new
product feature has a backend and frontend
component. There may be some shared code
between to two product sectors. Maybe the
backend developer creates a data structure that the
frontend will also need to utilize. The frontend
developer could use git cherry-pick to pick the
commit in which this hypothetical data structure
was created. This pick would enable the frontend
developer to continue progress on their side of the
project.
Bug hotfixes
When a bug is discovered it is important to deliver a
fix to end users as quickly as possible. For an
example scenario,say a developer has started work
on a new feature. During that new feature
development they identify a pre-existing bug. The
developer creates an explicit commit patching this
bug. This new patch commit can be cherry-picked
directly to the main branch to fix the bug before it
effects more users.
Undoing changes
and restoring lost
commits
Sometimes a feature branch may go stale and not
get merged into main . Sometimes a pull request
might get closed without merging. Git never loses
those commits and through commands like
git log and git reflog they can be found and
cherry picked back to life.
a - b - c - d Main
\
e - f - g Feature
git cherry-pick commitSha
git checkout main
git cherry-pick f
a - b - c - d - f Main
\
e - f - g Feature
-edit
--no-commit
--signoff
Summary
Cherry picking is a powerful and convenient
command that is incredibly useful in a few
scenarios. Cherry picking should not be misused in
place of git merge or git rebase. The git
log command is required to help find commits to
cherry pick.
Next up:
Git SSH
Keys
START NEXT TUTORIAL
Powered By