I'm using the "Git Flow" branching model, with a master branch and a develop branch. I'm working on a major new release, so my develop branch is wildly different from my master branch. This creates a problem anytime I need to make a hotfix on the master branch and merge it back into develop. There are almost always conflicts, and it's becoming a real pain.
What is the best way to manage this? It would be easier for me to make the small hotfix changes on develop manually and then merge everything into master when I'm ready without merging master back into develop. Is this possible?
master — this branch contains production code. All development code is merged into master in sometime. develop — this branch contains pre-production code. When the features are finished then they are merged into develop.
A Gitflow hotfix branch is only required when a critical bug or security flaw is found in live, publicly facing and globally accessible applications or binaries. The flaw is in a tagged commit on the Git master/main branch, and it has to be addressed immediately.
The simplest way to get some commits from one branch to another is cherry-picking.
Assuming that your fix in master
has the commit hash HASH
and you want to take that hotfix into your devel
branch, do a git checkout devel
followed by a git cherry-pick HASH
. That's it.
If you want to take all changes from master
into devel
, you can achieve that with
git checkout devel git rebase master
If you have the opposite scenario (you make a hotfix during development in a devel
branch and want to take that fix into master
before devel
gets fully merged into master
), the workflow is quite similar. Assuming that the hotfix has the hash HOTFIX_HASH
, do this:
git checkout master git cherry-pick HOTFIX_HASH
Now, the commit is present in master
and devel
. To get around this, type
git checkout devel git rebase master
and the commit will disappear from devel
since it's already present in master
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With