Considering you are working on a bugfix that needs to be merged into a release branch
- Make sure your branch is merged into develop
- Keep the SHA for the above merge handy
- Make sure you have latest target release branch pull in your local system
Picture - SHA of merge commit
Let's assume that your branching model is as follow
picture of git branching model here
You are targeting to merge your fix in branch named release/march/t2
Your branch name with bugfix is named codername/bugfix/regression/T001_serious_bug
Merge SHA is b3c5207e-b0e4-11ec-b909-0242ac120002
- Fetch release branch
git fetch origin release/march/t2
git checkout release/march/t2
- Create a new branch from release branch
git checkout -b codername/bugfix/regression/cherrypick_release_march_t2/T001_serious_bug
- Git cherrypick
release/march/t2
git cherry-pick b3c5207e-b0e4-11ec-b909-0242ac120002
Note: If there are merge conflict, remember that HEAD is the release branch and incoming changes are your changes. So pick wisely. It is recommended to give preference to HEAD if your (incoming) changes can easily re-done.
- Commit and push
That's it. You can now commit and push your changes
git add .
git commit -m "Cherrypicked T001 bugfix and resolved merge conflicts"
git push origin codername/bugfix/regression/cherrypick_release_march_t2/T001_serious_bug
- You can now create a Pull request from
codername/bugfix/regression/cherrypick_release_march_t2/T001_serious_bug
to target branchrelease/march/t2