3

I merged my development branch to staging branch but I can't see the merge commit on the staging branch. What am I doing wrong? My workflow is as follows.

  1. Checkout development branch and make some changes
  2. Pull development branch
  3. Commit development branch to local repo
  4. git checkout -q staging
  5. git merge development
  6. git push origin staging:staging
  7. git checkout -q development
  8. git push origin development:development

I use VS Code GUI for git tasks. I have another dev working in the same project. For some reason in both branches, the commit history looks exactly the same. Earlier it used to show the merge commit without any issue but not anymore. Neither of us are able to figure out where things went wrong.

suharsha
  • 95
  • 1
  • 3
  • 12

1 Answers1

2

When you perform a merge between two branches with Git and the branch you are merging is a strict superset of the branch you're merging into, Git performs what's called a fast-forward merge, which basically means that the branch you're merging into is just directly updated to be exactly the same as the other branch. In other words, no merge commit is created.

However, sometimes this is undesirable and you want to create a merge commit regardless. You can do that by using git merge --no-ff. So in your example, at step 5, you'd run git merge --no-ff development.

This can be confusing because most hosting platforms like GitHub always perform a merge commit when merging, even though Git does not.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thank you @bk2204. I think this explains whats happening now. But any reason as to why it used to happen earlier and not anymore? – suharsha Oct 08 '20 at 01:24
  • If there are commits in `staging` that are not in `development`, then Git cannot perform a fast-forward and must create a merge commit. So either that happened, or you used a tool (e.g., a hosting platform or an editor integration) that always performs merge commits. – bk2204 Oct 08 '20 at 01:26
  • This clears everything up. Now I see what has happened. Thanks alot. – suharsha Oct 08 '20 at 01:48
  • @suharsha a fast-forward merge updates the branch pointer to the same commit as the target branch. – evolutionxbox Oct 08 '20 at 11:18