git - 除非我克隆,否则我无法获得 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/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 url
origin
git remote set-url origin url
或者您可以只指示您的 Git 创建该设置:
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
例如,在 bash 中(或直接在合适的编辑器中编辑配置文件)。
推荐阅读
- sql-server - MDX:如何不为每个 Measure 编写单个 Scope 语句?
- javascript - Vue 3:为什么在更新对象之前获得相同的值
- android - 如果设备上缺少 HMS,则防止 @hmscore 显示初始弹出窗口
- spring-boot - Openshift 4.19 (Kubernetes 1.19) Tomcat spring app 使用配置映射条目覆盖部署的文件清除完整的部署目录
- javascript - 具有值语义的列表
- mysql - 如果值在mysql中包含非数字字符,如何创建条件?
- jenkins - Jenkins 将服务器指向创建的域
- r - 防止 stargzazer 将列名分散到多个列上
- angular - 单击 Angular 11 中的按钮时,如何关闭所有活动的引导程序 4 模式?
- javascript - How to add headers to this request?