Reputation: 703
I am kind of new to git and have a question regarding branching and merging those branches.
Let's say in my project repo I have 3 "main" branches: Alpha, Beta, Production.
Here is a scenario I am facing:
I currently work on the Alpha branch on my local machine. I create a new branch from Alpha, let's call it feature/newFeature
. After creating the feature I commit and push the changes and then I merge feature/newFeature
into the Alpha branch for QA to test. If QA approves, then it gets merged into Beta, then Production, etc.
Now, after feature/newFeature
has been merged into Alpha (and not any other branch yet) I create another branch from Alpha, call it fix/hotfix
. After fixing what needs to be fixed I merge this branch into Alpha as well.
But (and here is the problem I am facing), let's say that fix/hotfix
has been tested and is working and can be merged into Beta, but feature/newFeature
is still being tested on Alpha. If I try to merge the fix/hotfix
branch into Beta, it will also merge changes from the feature/newFeature
branch into Beta (which I obviously don't want because it is still being tested).
I understand why this happens, because when I merge feature/newFeature
into Alpha and then create the fix/hotfix
branch from Alpha after that merge, the fix/hotfix
branch also contains the changes from the feature/newFeature
branch.
My question is: Is there any way to do it in such a way that I can merge the fix/hotfix
branch into Beta without it also merging the previous branches/changes that shouldn't be merged yet?
Upvotes: 1
Views: 538
Reputation: 516
You can always copy fix/hotfix branch and rebase it onto beta
git checkout fix/hotfix
git checkout -b fix/hotfix-copy
git rebase beta
That should leave you with the hotfix changes on beta branch. Then just merge the hotfix
Upvotes: 1