We have a master and a production branch. The master branch contains current developments while the production branch contains the stuff that is running on the server. From time to time, there is an important bugfix that has to be applied to both branches.
Currently we are just cherry-picking the commit after creating it on the master branch. But this sometimes creates merge conflicts when we are merging the branches. Are there alternatives?
Cherry picking has a negative connotation as the practice neglects, overlooks or directly suppresses evidence that could lead to a complete picture.
A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.
With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined.
You can create a new branch (let's call it bugfix-a
) at the merge base of master
and production
git checkout -b bugfix-a $(git merge-base master production)
Apply your bugfix in that branch
>>/path/to/file echo 'this fixes the bug'
git add /path/to/file
git commit -m 'important bugfix'
Then, merge this new branch to both master and production:
git checkout master
git merge bugfix-a
git checkout production
git merge bugfix-a
That way you should be able to merge master and production at a later date and Git will be clever enough to figure out which commits to pick.
(Monotone – yes, it's not Git – calls this workflow daggy fixes)
Create a separate branch for each hotfix, and merge it into both your development branch and your production branch.
The gitflow model works really well in general, and I'd recommend checking this out: http://nvie.com/posts/a-successful-git-branching-model/
Your master branch is analogous to their develop branch, and your production branch is analogous to their master
You could use Gitflow. I think the 'hotfix' handles your scenario.
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