Git pull asks me to write merge message

Solution 1:

git pull is basically two actions at once: git fetch followed by a git merge (unless you use git pull --rebase, in which case you can guess what happens).

The reason you're seeing this is because Git can't do a fast-forward merge, like it can most of the time. The reason for that is usually because you've git committed locally to the branch you're trying to pull, and now you need to merge the remote changes with your local ones.

It's also worth noting that Git pre-populated the merge message for you, so you don't really need to type anything. Just save and exit, and the merge should be complete. (Unless, of course, there are merge conflicts).

Solution 2:

Linus Torvalds explains it best:

Spreading the word about an upcoming 'git' UI change, since I'm largely to blame.

This change hopefully makes people write merge messages to explain their merges, and maybe even decide not to merge at all when it's not necessary.

I've been using that git feature for the last few weeks now, and it has resulted in my merges from submaintainers having various notes in them (well, at least if the submainter gave me any). So I'm trying to lead by example.

But if you don't like explaining your merges, this might be annoying. Of course, if you don't explain your merges, you are annoying, so it all evens out in the end. "Karmic balance", so to say.

Source: https://plus.google.com/+LinusTorvalds/posts/SrePhcj6XJe

Solution 3:

If you were trying to merge master to mybranchSample branch, then this is perfectly normal.

Git merges master to mybranchSample (when you did git pull origin master from mybranchSample branch) and commits the merge changes for you (unless there is any conflict) and gives you the pre-populated message. You can just save and exit.

BUT If you were just trying to get the latest code from the remote master branch to merge with local master branch, then you should checkout out to master and then pull from master.

from you statement

it merges master files into my files. And even though I havent worked on some files from master, it shows the files list in Green when I type git status.

I think you are trying to do the second one.

so, try:

git checkout master
git pull origin master

Solution 4:

The reason this is only happening to you is not that your config is different, but that the branch you're merging in is different.

The reason for the files in the diff that you did not change is that after a merge, the new commit has to parent commits: The commit you did last and the newest commit on master. The new commit contains all changes/files. So if you diff from new to your last commit you will see all the files as changed/added that were changed/added on master while your branch was out of sync with the master branch.

Solution 5:

I think you have an issue with the branches... The 2 possible scenarios I could imagine you're facing:

1) You have a remote branch, mybranchSample, and you wanna work on it - you have nothing to do at the moment with the master branch (that is, you don't wanna merge your branch into master or vice versa). You say in your question

When I take pull from my branch after fetch like ...

But what you do is git pull origin master, which pulls from master. Instead, you should be able, with git version >= 1.6.6, to checkout your remote branch using

git fetch
git checkout mybranchSample

2) You try to work on mybranchSample but wanna have the latest code from the master branch there. Then it makes sense that a merge might be necessary, as Anand S said.