Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What are Git rebase and cherry-pick?

Hafiz Ahmad Shahzad

Git rebase

Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The general process can be visualized as the following:


From a content perspective, rebasing is changing the base of your branch from one commit to another, making it appear as if you’d created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base. It’s very important to understand that even though the branch looks the same, it’s composed of entirely new commits.

Furthermore, git rebase is being done commit by commit, so the same conflicts can appear again and again.

git rebase master
rabase syntax

Git cherry-pick

Git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. Git cherry-pick can be useful for undoing changes.

When to use Git cherry-pick

Git cherry picking might not be a reliable and safe option in many scenarios, but it should be used for the following:

  • Team collaboration
  • Bug hot fixes
  • Restoring lost commits

How to use Git cherry-pick

The syntax for using git cherry-pick is as follows:

git cherry-pick commitRef
cherry-pick syntax

In this example, commitRef is a commit reference, and it can be found using git log.

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.




Hafiz Ahmad Shahzad
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring