Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I had 1 commit on my local branch, then to take the changes from remote branch into my local, I did a git pull on my local branch and to my surprise git said this.

# Please enter a commit message to explain why this merge is necessary,

# especially if it merges an updated upstream into a topic branch.  

I understand that I'm in vi editor.

My question is why git asked me to enter the message. I never faced it before.

My git version is: version 1.9.5-preview20141217

Thanks in advance!

1 Answer

0 votes
by (62.9k points)

Git is asking for a commit message because of either of the following mentioned options:

  1. You updated your git client

  2. You ne'er had a local branch which was ahead of the remote before

  3. Your git config was changed recently

How to avoid this:

Since your native repository is one 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 rebasing, i.e. add your commit to the top. You can do this with

git rebase or git pull --rebase

If this is indeed the behaviour you are looking for, you can set up 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.

Browse Categories