I have two branches, ServerA and ServerB. The code in both is nearly the same, but not identical. ServerB branched off of ServerA in the past. I want to create a new dev branch with code changes that will be merged into both of the server branches.
I could create dev by branching ServerA, but I don't want ServerA's differences to go to ServerB or vice versa.
Or I could create a separate devA and devB branches, but then changes common to both would have to be done twice, once in each dev branch.
Is there a way to create a single dev branch that I can merge into both server branches, that also allows me to continue to make server specific changes on each of the server branches?
I have tried merging, maybe an orphan branch or rebasing the new branch?
Sounds like you want to retroactively implement a "master" or "main" branch that contains all the common code, and have your "server" branches be branches off of it containing server-specific code.
Since
ServerAwas the original branch, it was the master branch up until you createdServerB. So that's where we'll start:ServerBbranches off fromServerA.masterbranch at this point:master. You can do this a number of ways:ServerAthat have equivalent commits onServerB. Use this method if you want recreate the history of common changes inmaster. If the commit cherry-picked fromServerAalso includes changes specific toServerA, you can usegit cherry-pick -nto give you a chance to remove those specifics, or you can usegit commit --amendto fix them after each cherry-pick.ServerAandmaster, then use the GUI to copy/merge individual changes intomasterthat belong inmaster. Commit those changes intomaster.ServerAinto the worktree formaster, remove all theServerAspecific stuff, and then commit this tomaster:git checkout mastergit checkout master -- .to update the state of your worktree to the head of master without switching branchesgit add -pto selectively add only the common changes to the index.git commitperhaps with a message stating that the commit includes all common changes since the ServerA/ServerB split.masterbranch have already been made in the server branches. Here are two ways:masterinto both server branches. If you did the previous steps accurately, you can safely tell git to resolve all conflicts by accepting what's already in the server branch: Since all the changes inmastershould already be in each of the server branches, it should be an empty commit, even with the conflict resolution above.master. Do this if this is also what you place to do for the server branches going forward. If not, do themergedescribed above.ServerAwith its last commit before this process. It should be an empty diff. Do the same forServerB.master. You should see nothing in the diff that should be common to both servers.