Git pull asks me to write merge message

GitGit MergeGit Pull

Git Problem Overview


I pull from my branch:

git checkout mybranchSample
git fetch
git pull origin master

Then, Git gives me the following message:

> Please enter a commit message to explain why this merge is necessary,
especially if it merges an updated upstream into a topic branch

enter image description here

And after entering a commit message, it merges master into my files. And even though I haven't worked on some files from master, it shows the files list in green when I type git status.

This issue is not happening with my colleagues, but me only. What can be the reason behind this?

Git Solutions


Solution 1 - Git

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 - Git

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 - Git

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 - Git

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 - Git

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

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

  1. 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.

Solution 6 - Git

Just to try to give everyone a simple answer, and please correct me if I am not correct:

This seems to happen when you git pull after committing on the branch. Your local changes don't exist on the remote so it makes a commit to get everything synced.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPratikView Question on Stackoverflow
Solution 1 - GitMadara's GhostView Answer on Stackoverflow
Solution 2 - GittneView Answer on Stackoverflow
Solution 3 - GitAnand SView Answer on Stackoverflow
Solution 4 - GitMartin RauscherView Answer on Stackoverflow
Solution 5 - GitmischView Answer on Stackoverflow
Solution 6 - GitplushyObjectView Answer on Stackoverflow