Git Merge without removing the other branch to pull the changes
You have a branch - main
You have a branch with bug fixes - 5b
Now in order to merge your bug fixes changes to main,
pull latest changes from main branch:
git checkout main
git pull origin main
merge the changes in main branch to 5b branch (5b branch is up to date with main branch):
git checkout 5b
git pull origin 5b
git merge main
git push origin 5b
merge your 5b branch changes back to main:
git checkout main
git merge 5b
git push origin main
This will not remove your 5b(bug_fixes) branch or main branch. you can keep merging your bug fixes branch changes to main this way.
Related videos on Youtube
Comments
-
Vivek V Dwivedi almost 2 years
I searched a lot but was not able to find a confident solution(pardon me as I am new to git and maybe I didn't get some term well). So I will state my exact problem here:
I have a software (say in branch main) of which I just released v5.0 and then I created a new branch (say 5b) to fix all the issues that come in the branch.
All the new features are being added to main branch.
Now I have to supply a build with the new features to someone, but I also want to have all the bugfixes.
My logic says that I can pull all the changes from 5b, merge it with main and make a build.
The only problem is that I want to keep that branch 5b as it is so that other fixes can be added to it. While in the main, all the changes from 5b should be available.
Please let me know how to accomplish this. A step wise answer with a bit of detail will be really helpful.
Thanks,
-
Vivek V Dwivedi almost 11 yearsWill this add my changes to 5b branch too? I don't want to introduce this feature in 5b as this is used to send new bug fix releases to customers. This feature is only for a specif build in which I just want to add this feature.
-
Chubby Boy almost 11 yearsI am not clear. what do 'my changes' mean here? Do you mean by 'your local changes in 5b branch also get added to main branch'?
-
Alex Krauss almost 11 years@VivekVDwivedi No. Merging 5b into main only changes main, not 5b. Merge is asymmetric in that sense. In your example, 5b will usually be behind main, and whenever you make changes in 5b, you merge them back into main.
-
Vivek V Dwivedi almost 11 yearsGot it. I was under the concept that merge(as it literally means) is going to join both the branches in one.