Answers:
如果要复制主存储库中的所有对象,请在主存储库中执行以下操作:
git push --all <url-of-bare-repo>
或者,在裸仓库内进行访存:
git fetch <url-of-main-repo>
您不能进行拉取,因为拉取要与合并HEAD,而裸仓库没有。
您可以将它们添加为遥控器,以节省以后的输入内容:
git remote add <whatever-name> <url-of-other-repo>
那你就可以做
git push --all <whatever-name>
要么
git fetch <whatever-name>
根据您所在的存储库而定。如果<whatever-name>是origin,则甚至可以完全忽略它。
免责声明:我不是git guru。如果我说错了,我想得到启发!
更新:阅读评论!
git-fetch --all在裸仓库中进行内部操作时,没有看到对主存储库所做的更新,但是当从主存储库中推送它们时,git push --all <url-of-bare-repo>确实看到了中的更新git log。大概有一个简单的解释-有人可以解释吗?
git log是不会在裸仓库中显示这些更新。(也不会git log --all,通过克隆裸仓库创建的工作仓库也不会-通过git log --all或只是查看应该显示在此处的新文件)。亲自观察这是一个非常快速的测试。通常,我只是好奇我所缺少的。
git fetch -q origin master:master在本地裸存储库中进行操作。这将从github的master分支中获取新内容,并将您的本地master分支更新到该分支。
master:master是将HEAD移至远程仓库的必要条件。就我而言,由于一个问题,由于git丢失,我无法再连接到裸仓库。直到它得到解决我做了反向隧道,并使用取到中央回购:git fetch ssh://localhost:8765/... master:master和它的作品就像一个魅力。谢谢!
git fetch origin *:*
我使用以下命令创建了一个存储库
git clone --bare <remote_repo>
然后,我尝试使用托马斯的答案来更新裸机克隆,但这对我不起作用。为了获取裸仓库进行更新(这就是我认为Let_Me_Be提出的问题),我必须创建一个镜像仓库:
git clone --mirror <remote_repo>
然后,我可以在镜像存储库中运行以下命令以获取主存储库的更新:
git fetch --all
我通过阅读通过镜像镜像Git存储库遇到了这个解决方案
[remote "origin"]部分中,添加fetch = +refs/*:refs/*和mirror = true
除了重新创建之外,唯一的解决方案git clone --mirror是来自Gregor:
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
然后您就可以git fetch看到更新。奇怪的是,在此之前,即使已remote配置,它也没有列出分支git branch -a。
git remote update执行此工作。
--force和。--prunegit fetch
假设:
$ git clone --bare https://github.com/.../foo.git
取得:
$ git --git-dir=foo.git fetch origin +refs/heads/*:refs/heads/* --prune
注意:--git-dir=foo.git如果您cd先进入目录,则不需要。
origin未定义,则始终可以origin用原始存储库的路径/ URL 替换该部分。例如$ git --git-dir=foo.git fetch https://github.com/.../foo.git +refs/heads/*:refs/heads/*
经过一番混乱后,我发现这对我有用。
一旦:
git clone --mirror ssh://git@source.address:2000/repo
git remote add remote_site ssh://git@remote_site.address/repo
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
每当我想同步时:
cd /home/myhome/repo.git
git --bare fetch ssh://git@source.address:2000/repo
git fetch ssh://git@source.address:2000/repo
git push --mirror remote_site
git config remote.origin.fetch 'refs/heads/*:refs/heads/*')是关键。好答案,谢谢!
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'是答案。按下此命令后,我可以git fetch将仓库与远程仓库同步。
将裸存储库添加为远程存储库,然后使用git push。
对我来说,这种组合有效:
git remote add remote_site https://github.com/project/repo.git
git fetch -u remote_site +refs/heads/:refs/heads/*
git push --mirror
-u参数用于获取是必需的,否则我将收到错误消息:“拒绝获取到当前目录refs / heads / non-bare仓库的主目录”(另请参见https://stackoverflow.com/a/19205680/4807875)