Reputation: 477
Situation is like this. I have master and a branch that lets call it "image2"
So from the latest master up to date, I branched and created image2. I continued working on image2 branch.. and after a while a huge bug was found that also affected the master.
Now because master version is live, I needed to fix it there. I checkout to master, fix the bug in one of the files (lets call it file A), and go back to image2 to continue working on that branch. Thing is, now the fix is ONLY applied to master, and not to image2. The question is: what is the proper way to apply the master fix to image2? Because merging will cause troubles I guess, since the code of the file A in image2 has a lot of new things, but it also needs the fix that was applied in master.
Thank you
Upvotes: 1
Views: 36
Reputation: 12295
You are looking for a Git branching strategy called Git Flow
This defines a strategy for the numerous common development scenarios, including the "hotfix" scenario you describe in your question.
master
should always contain the code that is actively running in production. so you are correct to say when you need to fix a bug in prod, you create a hotfix branch off of master
. When the bug is fixed, the hotfix branch is deployed to prod and then merged to master
.
As feature branches can get stale, it's common to need to refresh the feature branches from either master
or develop
. Its your preference on if you want to merge master
/develop
into your feature branch or if you want to rebase your feature branch on top of master
. My personal preference is rebase.
Because merging will cause troubles
If you are referring to merge conflicts, then yes, it's very possible to have merge conflicts when you have parallel tracks of development (ie a hotfix
and a feature
branch). The idea is to solve the merge conflicts early, so they don't pile up. You'll need to resolve the conflicts eventually if you ever plan on getting your feature branch into master, but it's the responsibility of the feature branch to resolve these conflicts and stay current.
And here's the great gitflow branching diagram for reference. This should help illustrate how and when branches should be merged:
Upvotes: 1
Reputation: 359
If the image2 branch is not pushed to the remote repository you can rebase this branch on the new master. If it is already pushed to the remote repo you need to merge it with the new master.
If merging is such a big problem you could apply only the commit that fixes the bug in the master branch. For this purpose use the "cherry-pick" command.
On the image2 branch run git cherry-pick sha-value-of-the-commit
Upvotes: 1