Today I learned that if you have a big Pull Request on GitHub / GitLab, and you want to split it up into smaller PR’s, git’s rebase will automatically remove those commits from your big Pull Request if you open new smaller Pull Requests for them via cherry-pick:
- Open a big PR, realize it has too many commits. In this case, the branch was
vin-decoder-version-update#web-31721. - Find the commit SHA’s I want to extract to a new branch.
git log - Swap to master.
git checkout master - Pull the latest.
git pull --rebase - Create a new branch.
git checkout -b vin-decoder-docs#web-33020 - Pull the commits from the big branch to my new branch.
git cherry-pick 54321abcde09876fghijk112233lmnopqr998877stuvwxyz - Push up to GitHub.
git push origin vin-decoder-docs#web-33020 - Open a new PR on GitHub, get it approved, and merge it.
- Swap to master.
git checkout master - Pull latest master which now has those commits on it.
git pull --rebase - Swap back to your original big feature branch.
git checkout vin-decoder-version-update#web-31721 - Rebase master onto it.
git rebase master - Push it back up to the PR.
git push --force origin vin-decoder-version-update#web-31721 - Now the old commits you extracted are automatically removed from the commit history of this big PR, thus making it smaller!