user2094178 user2094178 - 1 year ago 99
Git Question

Right way to merge master into dev branch

When I have ongoing changes at

branch, and something breaks in production environment, then I switch to
, fix the problem and synchronize the production environment with the

Now I return to
branch. This branch is synchronized with

What is the proper way to bring to dev branch that fix from master?

Currently I do
git merge master
when at

But when merging like that, I noticed a new commit is created staging the modified files from

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.

Answer Source

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 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.