14

Every time I do a

git pull origin master

Git pops up an editor and asks me to write a comment about the merge before committing. Any idea why this might happen? Another developer is also doing work on master and has not had this issue.

As far as I can tell the branch configurations are correct. Other than this annoying merge commit that occurs when I pull, I am able to pull down changes and push up changes as normal.

5
  • Are you doing git commit first?
    – bozdoz
    Commented Mar 6, 2013 at 20:07
  • Are your pulls always just adding to what was before, or di you commit stuff meanwhile? Perhaps you should be doing git pull --rebase instead?
    – vonbrand
    Commented Mar 7, 2013 at 13:42
  • @bozdoz - yes I'm doing a local git commit first. @vonbrand - I'm not entirely sure what you're asking about the pulls Commented Mar 7, 2013 at 22:35
  • @Studio4Development Now, i face with your issue, please suggest me the way to solve this issue, thank you :) Commented Mar 14, 2014 at 7:00
  • did you find any solution. I see this with all my peers with only one repo. Not sure what setting is messed. Every time i pull, with 0 changes in my local machine, it promts merge, the merge would same files from previous commit. Commented Nov 30, 2015 at 8:52

3 Answers 3

6

git pull is git fetch followed by git merge. As of Git 1.7.10, git merge pops up an editor when merging (see the release notes). The other developer is probably using an older version of Git.

5
  • Is Git 1.7.10 a recent version? I've been using Git for about a year and throughout that time I have always updated my local branches using git pull - it never did what its doing now. If git pull has changed then what is the correct way to pull down changes from the origin server? Commented Mar 7, 2013 at 22:38
  • @Studio4Development: Git 1.7.10 was released 2012-04-06, although it may have taken a while for your operating system distribution to get the newer version. The behavior of git pull is still the same as it was, except it now gives you an opportunity to edit the message for the commit it generates. If you want the old behavior, you can do git pull --no-edit. (I recommend avoiding git pull altogether, however. It's an awful command, and I have stern words for any coworker I catch using git pull.) Commented Mar 9, 2013 at 18:52
  • What command or commands do you use to pull down changes from a remote repo for the branch you are currently working on? Commented Mar 13, 2013 at 15:39
  • @Studio4Development: see the bottom of my answer at stackoverflow.com/questions/15316601/… Commented Mar 13, 2013 at 16:29
  • I know this is old, but I'm getting this with git version 2.15.2 in 2018. What's confusing is no local changes exist and I just want to pull changes from another dev (1 new commit) and it's telling me it needs to merge, when there is nothing to merge. What's even stranger is that first attempt does not pull down anything, does the merge complaint, second attempt also complains but pulls down the comit...
    – MikeyT
    Commented Nov 12, 2018 at 20:49
2

I'm not a git expert, but I've run into this behavior and managed to get back into a working state, so here are my tips, all of which work using git version 2.28.0 (and likely earlier versions as well). I suspect someone who was more expert in git could streamline this answer further.

This happens to me when I've done something to screw up my local master/main branch that causes it to be out of sync with the one it's supposed to be tracking. I haven't yet figured out what I've done to mess it up to begin with, as it hasn't happened frequently enough for me to diagnose the mistake in my behavior. [Update: I think I've now seen one behavior in my own workflow that causes this. I go to GitHub to view a PR and use the copy link from the "view command line instructions" information for how to get a copy of the PR in my workspace. The first of the two commands that are copied is git checkout -b .... However, sometimes, I inadvertently do this in a workspace that already had a branch with that name (typically, I've already tried an earlier draft of the PR), so the command fails, I'm still on my master/main branch, and then the next command gets pasted in and merges the branch into my master/main. Then it takes me awhile to realize that things got messed up].

There are two ways I notice that I've gotten into this state:

  • via the editor window popping up when I do git pull origin master (as noted in the OP)
  • when a PR that I've pushed to GitHub shows commits of the form Merge branch 'master' of https://github.com/[myOrg]/[myRepo] into master

Here's how I fix this when it occurs:

  • First, I find the oldest merge commit with this message in my branch's history:
    • browse the log: git log
    • search back in time for the oldest commit with the message Merge branch 'master' of https://github.com/[myOrg]/[myRepo] into master
    • look for the SHA of the commit just prior to that (i.e., the point where my master branch diverged from the one it's supposed to be tracking)
  • Back my branch up to that SHA: git checkout [SHA]
    • this will put your branch into 'detached HEAD' state
  • Rename my messed up master branch to get it out of the way git branch -m master master-broken (optionally, you could delete it, but this is safer, and you can always delete it later)
  • Rename my current detached HEAD branch to master: git checkout -b master
  • Catch the branch back up to where it should be: git pull [upstream source] master (where, in the OP's case, I'd expect this to be git pull origin master)

A key insight to understanding this fix is to realize that there's nothing deeply special about the master branch—it's just a convention. So there's no problem with deleting it (or renaming it) and creating a new one with that name.

0

I don't know why this happens but I may provide a solution. As you noticed, it only happens for you and not for other developers. So something is broken on your side. I had this issue as well, as a consequence the history didn't look clean. A radical solution was to delete master locally and refetch it, as simple as that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.