[英]How can I synchronize git branches between bare repositories?
我有一个裸存储库,它的origin
是在远程机器上。
我想将其分支下载到本地裸仓库中。 即我想在分支列表中使用git branch -vva
命令查看它们,如下所示:
* master 0bc84f0 [origin/master] something...
remotes/origin/HEAD -> origin/master
remotes/origin/master 0bc84f0 something...
在非裸存储库的情况下, git pull --all
也同步分支(它使远程分支在本地存储库中可见),但是在裸存储库的情况下,拉不可能。
如何在此方案中同步远程分支?
注意: git --fetch
不起作用,远程分支在它之后仍然是不可见的:
$ git remote -v
origin git://host/project.git (fetch)
origin git://host/project.git (push)
$ git branch -vva
* master 4085a31 ...something
$ git fetch
From git://host/project.git
* branch HEAD -> FETCH_HEAD
$ git branch -vva
* master 4085a31 ...something
附加信息:我的config
如下:
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git://host/project.git
我的config
在新克隆(也裸露)回购:
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = git://host/project.git
解决方案#1:
您需要将您的仓库转换为镜像仓库:
git remote add --mirror=fetch origin <url>
git fetch
在获取后,镜像存储将保持与本地引用同步的原始引用。 它的缺点是,镜像应该是远程仓库的精确副本,可能不是您的目标。
解决方案#2:
(使用评论从@peterh扩展):
在git配置中(在裸仓库的情况下只需repo/config
),a
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
应该存在。 如果没有,它可能是一个非平凡的git功能,或git bug。 你可以手动修复它。 之后, git fetch
将起作用。
git fetch
应该已经足够了。
只是为了测试,只需尝试将您的裸仓库再次克隆到新的本地仓库中。 如果远程跟踪分支在那里,请参阅。
git clone git://host/project.git newproject
cd newproject
git branch -avv
我做了一个新的克隆,我仍然看不到任何远程分支,尽管原点指向正确的URL。
情况仍然相同,你可以在我的问题的最后看到(正确的原始URL,但仍然没有远程分支)
这意味着那些远程分支机构首先不在远程仓库中。
克隆的默认提取refspec是
fetch = +refs/heads/*:refs/remotes/origin/*
如果远程仓库有任何其他分支,它们也将被克隆。
如果配置没有显示任何fetch
密钥(如git config -l
),请尝试添加一个:
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
用以下方法检查:
git config --get remote.origin.fetch
在“ git fetch
不能获取所有分支 ”中查看更多信息。
那么真正的问题就是:在OP的配置中, git clone
克隆只有master并且不包含fetch refspec?
也许设置了Git环境变量 ?
例如, GIT_TEMPLATE_DIR
(包括默认配置)
简单地增加抓取的Refspec 不能解决实际问题。
要解决实际问题,需要更多信息(Git版本,操作系统版本......)
在以下行的裸仓库中添加到您的配置:
fetch = +refs/*:refs/*
您的配置将如下所示:
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git://host/project.git
fetch = +refs/*:refs/*
然后在你的回购做
git --bare fetch
将下载新的分支机构
git pull
是运行git fetch
以同步分支的简写,然后是git merge
以将本地副本与远程版本合并。
从你的裸仓库,你需要做的就是git fetch
来同步你的本地分支引用。
有关详细信息,请参阅此处: https : //git-scm.com/docs/git-fetch
一个人必须从:
git clone --mirror git@host/project.git
这会创建一个裸仓库,并准备好接收更新,然后cd到您的project.git
并更新您当地的裸仓库:
git --bare fetch
只是测试它,就像一个魅力
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.