Time to time when working on a project using a fork from a git repository, situations arise that a pull request need to be made to the master
repository for a sub set of commits you made to the fork. The following are a set of steps which can help with accomplishing these scenarios.
On the git repository in your local machine created from your fork, create a new branch
1
git branch cherry-branch origin/master
The assumption is that there is only one branch in your fork and the master repository and origin is pointing to your github fork.
Switch to the new branch created
1
git checkout cherry-branch
You can verify that you are on the correct branch by running the command
1
git branch
Identify ids of the commits you want to include into the pull request from your github fork.
Issue a git cherry-pick command to include the commits into the new branch
1
git cherry-pick COMMIT-ID
Push the new branch to your fork
1
git push origin cherry-branch
On github you can now see the new branch in your fork with only the commits selected. Now a pull request to the master repository.
What if there are multiple branches on the master repository and your fork and you want to send a pull request from a particular branch of your fork
to a branch in the master repository.
Create a clone of the master repository branch you are interested in
Now the branch “cherry-branch” will be show up in github UI with the changes selected. A new pull request can be created for the changes to be committed into the master repository.
Once the changes are merged, the branch can be deleted and the local repository created can be removed.