user2094178 user2094178 - 2 months ago 28
Git Question

Right way to merge master into dev branch

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.

Answer

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.