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
I referred this question but I'm still finding it hard to understand. Thanks.
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
git pull
. There are lots of explanation of this behavior on the internet, this does a good job of explaining it.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With