13

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.

Studio4Development
  • 725
  • 1
  • 6
  • 18
  • Are you doing `git commit` first? – bozdoz Mar 06 '13 at 20:07
  • Are your `pull`s always just adding to what was before, or di you `commit` stuff meanwhile? Perhaps you should be doing `git pull --rebase` instead? – vonbrand Mar 07 '13 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 `pull`s – Studio4Development Mar 07 '13 at 22:35
  • @Studio4Development Now, i face with your issue, please suggest me the way to solve this issue, thank you :) – Rong Nguyen Mar 14 '14 at 07: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. – sandeep koduri Nov 30 '15 at 08:52

3 Answers3

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.

Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
  • 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? – Studio4Development Mar 07 '13 at 22:38
  • @Studio4Development: Git 1.7.10 was [released 2012-04-06](http://article.gmane.org/gmane.comp.version-control.git/194905), 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`.) – Richard Hansen Mar 09 '13 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? – Studio4Development Mar 13 '13 at 15:39
  • @Studio4Development: see the bottom of my answer at http://stackoverflow.com/questions/15316601/why-is-git-pull-considered-harmful/15316602#15316602 – Richard Hansen Mar 13 '13 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 Nov 12 '18 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.

Brad
  • 3,839
  • 7
  • 25
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.

jperl
  • 4,662
  • 2
  • 16
  • 29