I had a large PR that colleague asked me to split into multiple smaller PRs. I reviewed different tools but those either:
- split the PRs based on commits or
- unrolled PRs into a linked list of branches
Neither of these seemed like a good choice because both assumed that somehow timeline matters when it comes to splitting. But I think that the right grouping is not time based but file based. I couldn’t find anything that would do the trick so I wrote this gist: https://gist.github.com/ierceg/0954512137489c9b46cb9e99c4adbf82
I tried to cajole ChatGPT to summarize it, somewhat succinctly, but it was too focused on the implementation details. So here goes my summary:
This interactive script allows you to split any branch into as many different branches that you need, based on the interactive file selection. Each selection is committed into a separate branch and the process is continued until there are no more files left in the diff between the target+split and source branches. It then pushes all the branches to remote and optionally opens pull requests on GitHub. The script is idempotent. It assumes that you don’t care about the commit history of feature branches.
I should of course add that when splitting on files, there are no expectations that every PR should pass all the tests. It may but that would be rare. Rather the process I envision is:
- Split the bunch into a bunch of branches and have at least one that will pass all the tests (e.g. db migrations)
- The branches that pass all the tests can be reviewed and will be hopefully approved and merged.
- Rerunning the script at that time should (in the future) merge the target branch (e.g.
master
) into each split branch and push out the changes. - Then rinse, repeat until there are no more PRs left.
- If more work is needed on any of the branches, it should be done on the source branch (the branch that was split). Rerunning script after that should (in the future) figure out where the update files go. Maybe sometimes a file needs to be moved between the branches.
Another way to rinse, repeat is to merge all the mergable PRs and then merge the target branch into the original source branch and then repeat the whole process. That would have to nuke the older split branches and PRs but that could be provided for.
Last modified on 2023-12-27