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 hotfix
into main
, and another to merge hotfix
into develop
. 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 example hotfix-1.2.3
(or hotfix/1.2.3
). Protect the branch so that PRs are required to merge into it, just like for develop
and main
.hotfix
branch.hotfix
branch.hotfix
into main
and also into develop
. 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:
Currently, I just close PR and merge them in local and push it to the remote.
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 release
and hotfix
branches, is to first merge them into main
, and then merge main
into develop
(instead of also merging the release or hotfix branch into develop
). Doing this is functionally equivalent, except that the merge commit that goes on main
gets brought down to develop
immediately, instead of with the next hotfix
. It's slightly cleaner this way and it also means that develop
and/or your release
branches are always fully up to date with main
, in both state and commits. (Doing it the way Git Flow is documented only brings the state up to date.)