Creating Pull Requests for Small Changes - SRF-Consulting-Group-Inc/iris GitHub Wiki
When you finish developing a major feature and want to merge it into the IRIS mainline, it is fairly straightforward. In that case, you can simply push your branch to your fork, then use the GitHub web interface to create a pull request to merge your feature branch into the mnit-rtmc/iris/master branch.
But what if you make a small change (say a bug fix) that you want to merge as soon as possible? If you try to create a pull request with the branch you are working on, it will end up containing all the commits you have made, which you may not be ready for.
One of the ways you can work around this by creating a dummy branch that is up to date with mnit-rtmc/iris/master
, then use git cherry-pick
to pick out the specific commits you want to merge. This requires a few more steps, but it allows you to get small changes into mainline before you finish your other work, which may be desirable in some cases.
Example
Say you are working on a branch called feature
to develop a fancy new feature. Part of the way through the development process, you discover a bug that causes a weird problem in a few edge cases. The fix is quick and easy (just a few lines), so you make it and push it to the feature
branch of your fork. Now you want to send it to the mainline so others can benefit from it, but the commit containing the change is on top of 20 other commits that partially implement your feature, and you don't want to send those yet until you are done.
To work around this, first create a new branch without any of your commits (even with mnit-rtmc/iris/master
). To do this (as of now), branch off the mnit_tracking
branch. This command will create the bugfix
branch based on the mnit_tracking
branch then check it out for you:
git checkout -b bugfix mnit_tracking
After this, you may need to update this branch from MNIT's repository before doing more. If you don't already have it set as an upstream for your local repository, run:
git remote add upstream https://github.com/mnit-rtmc/iris.git
Then run:
git pull upstream master
The bugfix
branch that you created will now be in sync with mnit-rtmc/iris/master
. Now you can apply the changes you want to this branch. First lookup the ID of the commit(s) you want from the other branch (you can use git log feature
or the GitHub web interface to help identify them). Then use the cherry-pick command to apply that commit (0509dc4 in this example) to the bugfix branch:
git cherry-pick 0509dc4
If you have more than one commits to apply, repeat the above command with those IDs.
Now push the new branch to your fork with:
git push origin bugfix
And now you can use the GitHub web interface to create a pull request to merge your bugfix
branch into mnit-rtmc/iris/master
. That request will contain only the commit(s) you want to send now, allowing you to finish your work on the other feature at your leisure.