21

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.

user2094178
  • 9,204
  • 10
  • 41
  • 70
  • Does this answer your question? [How to "git pull" from master into the development branch](https://stackoverflow.com/questions/20101994/how-to-git-pull-from-master-into-the-development-branch) – dsimic Aug 22 '23 at 04:25

1 Answers1

25

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.

Makoto
  • 104,088
  • 27
  • 192
  • 230