DEV Community

David Berri
David Berri

Posted on • Originally published at dberri.com on

1

How to use git cherry-pick

This command is extremely useful when you need only one or few commits from one branch in another branch, but don't want or cannot merge.

Let's say that in your application you use the branch main to deploy to production and develop new code in another branch, say dev. You implement a few features, but realize one of them needs to be merged to main soon and cannot wait for you to finish whatever you were developing in the dev branch.

You can use the following git commands:

# Find and copy the commit hash that you want to send to another branch
git log

# change to the branch where this commit is needed
git checkout <branch-name>

# execute the cherry pick using the hash you copied earlier
git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode

If there are any conflicts, resolve them and commit the new code. Done.

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs