Why git asks to enter a commit message to explain why this merge is necessary

From Git Documentation:

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD

As to your question about: WHY

  1. Why is Git creating a MERGE commit: That is the default behavior of git pull. There are lots of explanation of this behavior on the internet, this does a good job of explaining it.
  2. Why is Git asking for a commit message now: Three possible options come to my mind:
    • You updated your git client
    • You never had a local branch which was ahead of the remote before
    • Your git config was changed recently

How to avoid this:

Since your local repository is 1 commit ahead, git tries to merge your remote to your local repo. This can be handled via merge, but in your case, perhaps you are looking for rebase, i.e. add your commit to the top. You can do this with

git rebase or git pull --rebase

If this is indeed the behavior you are looking for, you can setup your git config to make rebase a default option for your git pull

Set it up globally with:

git config branch.autosetuprebase always # Force all new branches to automatically use rebase

Or you can set it up per branch:

git config branch.*branch-name*.rebase true # Force existing branches to use rebase.

Leave a Comment