首页 > 解决方案 > 除非我克隆,否则我无法获得 origin/master

问题描述

使用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)

在最初推送到裸 git 存储库的存储库中,使用以下命令设置其 url:

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.

标签: git

解决方案


如果您检查配置文件.git/config

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*

不太好的就是缺少这个fetch =设置。

缺少fetch = ...设置是为什么git fetch在不太好的存储库中永远不会创建origin/master. 它在 at 调用 Git origin,看到另一个 Git 有一个master,并带来他们有的任何你没有的提交......然后没有创建origin/master,因为它没有告诉它这样做。你最终会看到:

 * branch            master     -> FETCH_HEAD

相比之下,在好的存储库中,runninggit fetch在 处调用 Git origin,看到另一个 Git 有一个master,带来他们没有的任何提交......然后根据origin/master设置创建或更新fetch =

运行git clone会创建提取设置。运行会创建它——所以shams.kool 的评论建议删除然后重新创建会起作用——但运行不会创建 fetch 设置。git remote add origin urlorigingit remote set-url origin url

或者您可以只指示您的 Git 创建该设置:

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'

例如,在 bash 中(或直接在合适的编辑器中编辑配置文件)。


推荐阅读