When I have ongoing changes at dev
branch, and something breaks in production environment, then I switch to master
, fix the problem and synchronize the production environment with the master
branch.
Now I return to dev
branch. This branch is synchronized with test
and staging
environment.
What is the proper way to bring to dev branch that fix from master?
Currently I do git merge master
when at dev
branch.
But when merging like that, I noticed a new commit is created staging the modified files from master
.
I was under the impression when merging that the commits created at master when applying the fix would just be inserted into the dev branch.
In GitHub Desktop, click Current Branch. Click Choose a branch to merge into BRANCH. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button.
First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into.
Provided that your staging environment is clean (as in, you don't have any uncommitted or unstashed changes on your development branch)...
git merge master
...is the idiomatic* way to merge changes from your master branch in.
When you merge, you bring in all of the changes which are at the tip of that branch, so you'll be bringing in all of the changes from master at once, and you'll have to deal with merge conflicts if they exist. If you can't fast-forward the changes over from master to dev, then you'll also get a merge commit.
The reason that you may see a lot of commits may be due to the fact that you can't fast-forward your dev branch to line up with master. This shouldn't put you off; simply commit and push those changes into your dev branch as well.
*: You can also do git rebase master
while on dev
, but this has a much higher risk since you're rewriting history. Makes for a cleaner history, though.
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