DEV Community

Yacine C
Yacine C

Posted on

Why use git cherry-pick instead of git rebase

Debugging can quickly become difficult when your rebase is significant. Fortunately, you can use cherry-pick to help you rebase your branch commit by commit.

Let's consider a practical example: you are developing on a branch named feature, and you need to rebase this branch onto main.

First, ensure that you are on the feature branch. Then, copy the commit hash that you want to apply to feature and use the following command:

git cherry-pick hash_from_main_branch
Enter fullscreen mode Exit fullscreen mode

If the cherry-pick operation creates a conflict, you will need to resolve it. The advantage of this approach is that you can deal with a single commit and a smaller conflict. You know which commit created the conflict, making it easier to solve the problem.

Top comments (0)