I'm now using gitflow strategy and github as a remote repository.
Recently I encountered a problem of merging hotfix PRs into both develop and main branch.
It seems the Github supports only one target branch for a PR and doesn't know whether a branch is feature or hotfix.
Currently, I just close PR and merge them in local and push it to the remote.
Is anybody have nice idea or github feature I can use to merge a hotfix branch to both develop and main branch at the same time?
Thanks in advance.
Note that One PR = One merge. All you need are two separate PRs, one to merge
hotfixintomain, and another to mergehotfixintodevelop. Regarding the code reviews, it's best for a Git Flow Hotfix branch to also be a protected branch, which itself requires a code review. For example:main, for examplehotfix-1.2.3(orhotfix/1.2.3). Protect the branch so that PRs are required to merge into it, just like fordevelopandmain.hotfixbranch.hotfixbranch.hotfixintomainand also intodevelop. These 2 merges are "Git Flow" merges and can possibly be automated and bypass the PR process. Or you can create 2 more PRs for the two merges. Note that these 2 PRs do not require regular code reviews like the PR in step #2. Since these PRs could be automated, if you need a human to approve, they can likely just do a quick sanity check that the merges are correct.Regarding:
Doing that will work, and is kind of the same thing as automating the 2 merges as described in step #4. If you go that route I would recommend scripting it so that it's repeatable and less prone to error. Note that when you have merge conflicts, you will need to manually intervene regardless.
Tip: When using Git Flow, my personal preference when completing both
releaseandhotfixbranches, is to first merge them intomain, and then mergemainintodevelop(instead of also merging the release or hotfix branch intodevelop). Doing this is functionally equivalent, except that the merge commit that goes onmaingets brought down todevelopimmediately, instead of with the nexthotfix. It's slightly cleaner this way and it also means thatdevelopand/or yourreleasebranches are always fully up to date withmain, in both state and commits. (Doing it the way Git Flow is documented only brings the state up to date.)