Warren Rodrigues
How to cherry pick commits to be merged on Github

Blog

How to cherry pick commits to be merged on Github

25 Mar 2021

More of a personal note for future reference.

Working with a public repository on Github recently, I did the following:

Fork the project, clone the fork

git clone https://github.com/username/project-fork.git

Assign the original repo to a remote called "upstream"

git remote add upstream https://github.com/original-user/project.git

Get latest changes from upstream

git checkout master
git pull upstream master

Create a branch for the fix

git checkout -b branch-fix

Code the fixes in branch-fix

Commit my changes to branch-fix

Locally rebase the upstream branch into branch-fix

git pull --rebase upstream master

Change back to master

git checkout master

Now DO NOT merge the whole branch, BUT cherry-pick only the commit(s) from branch-fix, using commit hash.

The hash uniquely defines the commit - regardless of the branch it is in.

git cherry-pick hash123

Push branch-fix up to my fork

git push origin branch-fix
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×