使用git version 2.11.0
。
在克隆的存储库中:
git remote show origin
* remote origin
Fetch URL: ssh://path/to/repo
Push URL: ssh://path/to/repo
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
在最初使用follwoing命令将其推送至裸git repo的存储库中,以设置其网址:
git remote set-url origin ssh://path/to/repo
我得到:
git remote show origin
* remote origin
Fetch URL: ssh://path/to/repo
Push URL: ssh://path/to/repo
HEAD branch: master
<Remote branch missing from here>
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
在所讨论的回购中:
当我git fetch
时,我总是收到消息:
From ssh://path/to/repo
* branch master -> FETCH_HEAD
Git遥控器似乎还可以:
$ git remote -v
origin ssh://path/to/repo (fetch)
origin ssh://path/to/repo (push)
Git推送似乎还可以:
$ git push -u
Branch master set up to track remote branch master from origin.
Everything up-to-date
但是--set-upstream-to
失败:
$ git branch master --set-upstream-to origin/master
error: the requested upstream branch 'origin/master' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
答案 0 :(得分:2)
如果您检查配置文件(.git/config
)中的好克隆与不那么好原始的文件,您会发现其中的一个(好文件)具有一个条目,该条目内容如下:或更少:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
不太好的人缺少此fetch =
设置。
缺乏fetch = ...
设置是为什么不太好的存储库中的git fetch
从不创建origin/master
的原因。它在origin
上调用Git,看到另一个Git有一个master
,并带来了您不拥有的所有提交...然后没有< / em>创建origin/master
,因为它没有任何指示。您最终看到:
* branch master -> FETCH_HEAD
相比之下,在良好的存储库中,运行git fetch
会在origin
上调用Git,看到另一个Git具有一个master
,并带来了您所做的所有提交't ...,然后 根据origin/master
设置创建或更新fetch =
。
运行git clone
创建访存设置。运行git remote add origin url
会创建它-因此shams.kool's comment建议删除然后重新创建origin
会起作用-但是运行git remote set-url origin url
不会创建获取设置。
或者您也可以指示Git创建该设置:
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
例如,在bash中(或直接在合适的编辑器中编辑配置文件)。