I have two branches: main for the old release and dev for the latest release. I need to manage hotfixes effectively across these branches. Specifically, I need to:
What is the best approach to ensure that hotfixes applied to main are also incorporated into dev?
Additionally, although now i have same codebase in both branches, how should I handle the situation where the dev branch is behind main due to differences in commit history from merge requests? What are the best practices for synchronizing these branches?
I expect to be able to merge hotfix to dev and main. If there is a better approach, please suggest it.
From the description of your branching strategy, you aren't really using Git Flow, since it doesn't appear that you're using release
branches and it's unclear how you're getting features from your dev
branch into main
. But since you tagged git-flow
, there are same concepts from it that will help you here:
dev
(akin to develop
in Git Flow), and get it stable enough that everything on dev
can be deployed to production. In order to do this you need to stop development of new features (code freeze) at some point and just focus on bug fixes. One of the main reasons Git Flow was created is to avoid having code freezes, and this is solved by cutting a release
branch from dev
, and then you can have bug fixes worked on release
while new development continues simultaneously on dev
.dev
if you did a code freeze, or release
if you created it). Then merge that stable branch into main
. (Git Flow recommends using --no-ff
for this merge so the first parent of history shows you exactly what was deployed to production each time.) After merging release
or dev
into main
, merge main
back into dev
.hotfix
, merge hotfix
into main
when it's deployed, and then merge main
into release
if it's pending, or dev
if you don't have a pending release
. Specifically to your scenario: if you only have dev
and main
, after merging a hotfix into main
, merge main
back into dev
.Takeaways:
release
branches, main
should never be ahead of release
, except for perhaps a minute or so after merging in a hotfix before main
gets merged into release
.release
branches, main
should never be ahead of dev
, except for perhaps a minute or so after merging in a hotfix before main
gets merged into dev
.