I have a development branch called main
, a staging branch called staging
and production branch called production
. I want to push a hotfix to production branch.
First I created a new branch off main
:
git checkout main
git checkout -b hotfix
Then I merged the branch to main
:
git checkout main
git merge hotfix
then merged the branch to staging
in order to deploy first to staging environment and check that the branch works:
git checkout staging
git merge hotfix
Now I want to merge the hotfix branch to production
however merging brings a lot of other changes not-related to the hotfix. These other changes were not checked in staging
environment yet so I don't want to have them in production
. Therefore I decided to just cherry-pick
the commits related to the hotfix from the hotfix
branch into production
. I also had some conflicts when cherry-picking.
I'm wondering though if in the future there will be changes to the regions of code which I cherry-picked in main
and staging
, will they be reflected in production
? I'm afraid that git will not reflect them because of the cherry-pick and conflicts.
Is there a better way to handle hotfixes in git so that the above issues don't occur?