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.
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.
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:
git pull origin master
(as noted in the OP)Merge branch 'master' of https://github.com/[myOrg]/[myRepo] into master
Here's how I fix this when it occurs:
git log
Merge branch 'master' of https://github.com/[myOrg]/[myRepo] into master
master
branch diverged from the one it's supposed to be tracking)git checkout [SHA]
git branch -m master master-broken
(optionally, you could delete it, but this is safer, and you can always delete it later)git checkout -b master
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.
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