开发者

add remote + swap name with origin, gives error: "git fetch origin; git merge" works, != "git pull" has error -why/how?

I've searched high and low to understand this, and I feel it is just slipping through my fingers. There are similar, but not identical, QnAs here.

The problem:

$ git pull
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched.

Whereas git fetch gives nothing, followed by git merge origin which says Already up-to-date., which is what I expected had git pull worked 'properly'.

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "official"]
    url = git://github.com/freenet/wininstaller-official.git
    fetch = +refs/heads/*:refs/remotes/official/*
[remote "origin"]
    url = git://github.com/freenet/wininstaller-staging.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    tagopt = --tags
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "t"]
    remote = origin
    merge = refs/heads/master

$ cat .git/refs/remotes/origin/master
1a30b106723624321366f40a078c9ca4c28394ec

$ cat .git/refs/heads/master
1a30b106723624321366f40a078c9ca4c28394ec

Why does git pull give error, whilst git fetch/merge produce the expected output?

Background: I cloned a git repo, freenet/wininstaller-official.git, then saw wininstaller-staging.git and thought "there's likely some 开发者_JAVA百科not insubstantial overlap there, I ought to add 'staging' as a remote to the first repo". Yeah, now we're cooking with git! This will be so efficient.

Then I thought "staging might be better to track, let's call that origin, and have my local master track new origin/master". Wow! Uber-elte am I!

So I rename remotes as above, delete local master, checkout new master tracking new origin/master.

And git fetch; git merge seems to prove it works right!

But alas, git pull errors out. Woe is me. Not so uber-elite after all :(

TIA


The error from git pull is complaining that it can't find the branch that you've told it to merge from. I suspect that this is because you have tagopts = --tags configured for origin, and with that option, git fetch doesn't fetch branch heads. Try removing that line, and running git pull again.

To explain the pull / fetch-and-merge difference: when you manually run git fetch, it doesn't get the --tags options, so it does fetch the branch heads. So, after that point, origin/master exists and can be merged from.


One other note might be worth adding: it's more normal to use git merge origin/<branch-name>, which is more explicit than git merge origin. In that more unusual case, git is interpreting origin as the branch refs/remotes/origin/HEAD - i.e. the current branch (or commit) in the remote repository origin the last time you fetched from there. It's probably better to stick with git merge origin/<branch-name> to avoid confusion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜