Tho*_*mas 75
如果要复制主仓库中的所有对象,请在主仓库中执行此操作:
git push --all <url-of-bare-repo>
Run Code Online (Sandbox Code Playgroud)
或者,在裸仓库中进行取件:
git fetch <url-of-main-repo>
Run Code Online (Sandbox Code Playgroud)
你不能做拉,因为一个拉想要合并HEAD,一个裸的回购没有.
您可以将这些作为遥控器添加,以便将来节省一些打字:
git remote add <whatever-name> <url-of-other-repo>
Run Code Online (Sandbox Code Playgroud)
然后你就可以做到
git push --all <whatever-name>
Run Code Online (Sandbox Code Playgroud)
要么
git fetch <whatever-name>
Run Code Online (Sandbox Code Playgroud)
取决于你所在的回购.如果<whatever-name>是origin,你甚至可以完全放弃它.
免责声明:我不是一个git guru.如果我说错了,我想开悟!
更新:阅读评论!
aus*_*ten 66
我使用以下命令创建了一个存储库
git clone --bare <remote_repo>
然后我尝试使用Thomas的答案更新裸克隆,但它对我不起作用.为了让裸存储库更新(这是我认为Let_Me_Be所要求的),我必须创建一个镜像存储库:
git clone --mirror <remote_repo>
Run Code Online (Sandbox Code Playgroud)
然后我可以在镜像存储库中运行以下命令来获取主存储库的更新:
git fetch --all
Run Code Online (Sandbox Code Playgroud)
我通过阅读Mirror a Git Repository来了解这个解决方案
Col*_*ett 49
除了与重建唯一的解决办法git clone --mirror是从格雷戈尔:
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
Run Code Online (Sandbox Code Playgroud)
那么你可以git fetch,你会看到更新.奇怪的是,在此之前,即使有remote配置,它也没有列出分支git branch -a.
ant*_*tak 42
假设:
$ git clone --bare https://github.com/.../foo.git
Run Code Online (Sandbox Code Playgroud)
获取:
$ git --git-dir=foo.git fetch origin +refs/heads/*:refs/heads/* --prune
Run Code Online (Sandbox Code Playgroud)
注意:--git-dir=foo.git如果您cd首先访问该目录,则不需要.
sim*_*nvc 10
经过多次搞乱后,我发现这对我有用.
一旦:
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/*'
Run Code Online (Sandbox Code Playgroud)
每次我想要同步:
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
Run Code Online (Sandbox Code Playgroud)