DEV Community

José Miguel Álvarez Vañó
José Miguel Álvarez Vañó

Posted on • Originally published at jmalvarez.dev

16

How to cherry-pick a commit from another repository

To cherry-pick a commit from another repository you have to first add the other repository as a remote (a remote is a repository whose branches you are tracking). You have to give the remote a name.

git remote add <name> https://github.com/example.git
Enter fullscreen mode Exit fullscreen mode

Then, you have to fetch the branches of the remote.

git fetch <name>
Enter fullscreen mode Exit fullscreen mode

Now that you are tracking the other repository and have fetched the changes you can list the commits of a specific branch and cherry-pick a commit.

git log otherRepo/<branch>
git cherry-pick <commit>
Enter fullscreen mode Exit fullscreen mode

In case that you don't want to track the remote anymore you can remove it with:

git remote remove <name>
Enter fullscreen mode Exit fullscreen mode

More info about working with remotes here.

Resources

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (1)

Collapse
 
colbyfayock profile image
Colby Fayock

worked perfectly, thanks

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more