I maintain three codelines for each project: 'master' for latest development, 'test' for stabilization, and 'prod' for live code, plus any feature branches.
Periodically, I want to reflect all of the changes from one branch into another. Of course, pushing master into test to begin stabilizing for a new release. Or pushing test into prod to make the stable version live. But also, to bring bugfixes from test into master or even sometimes from prod into test (in the case of an urgent hotfix). There are also some branch-specific changes, such as URLs and keys. Git is wonderful, and I can't imagine the time it has saved me over other systems. But I'm not sure how to do this without running into trouble from time to time.
Deleting and recreating these three "primary" branches isn't practical because they back cloud environments, and because we have distributed developers. Similarly, rebasing is problematic because each of the branches is shared, and changes are pushed from each of them. I've been merging in both directions, as I did with other version control systems like Perforce: merge fixes from test into master, then new development from master into test. But that has caused serious issues that I don't fully understand.
How would you recommend managing these branches so that changes from each can be reflected into the others?
Thanks in advance for your thoughts!