git 如何更新我的裸仓库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3382679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I update my bare repo?
提问by ?imon Tóth
I created a bare repo to publish my repository, but I can't figure out how to update the bare repo with the current state of the main repository.
我创建了一个裸存储库来发布我的存储库,但我不知道如何使用主存储库的当前状态更新裸存储库。
采纳答案by Thomas
If you want to duplicate all the objects from the main repo, do this inside the main repo:
如果要复制主存储库中的所有对象,请在主存储库中执行以下操作:
git push --all <url-of-bare-repo>
Alternatively, do a fetch inside the bare repo:
或者,在裸仓库中执行 fetch 操作:
git fetch <url-of-main-repo>
You cannot do a pull, because a pull wants to merge with HEAD
, which a bare repo does not have.
您不能进行拉取,因为拉取要与 合并HEAD
,而裸仓库没有。
You can add these as remotes to save yourself some typing in the future:
您可以将这些添加为遥控器,以在将来节省一些输入:
git remote add <whatever-name> <url-of-other-repo>
Then you can simply do
然后你可以简单地做
git push --all <whatever-name>
or
或者
git fetch <whatever-name>
depending on what repo you're in. If <whatever-name>
is origin
, you can even leave it out altogether.
取决于您所在的存储库。如果<whatever-name>
是origin
,您甚至可以完全忽略它。
Disclaimer: I'm not a git guru. If I said something wrong, I'd like to be enlightened!
免责声明:我不是 git 大师。如果我说错了,我想开悟!
Update: Read the comments!
更新:阅读评论!
回答by austen
I created a repository using the following command
我使用以下命令创建了一个存储库
git clone --bare <remote_repo>
git clone --bare <remote_repo>
Then I tried to update the bare clone using the answer by Thomas, but it didn't work for me. To get the bare repository to update (which is what I think Let_Me_Be was asking), I had to create a mirror repository:
然后我尝试使用 Thomas 的答案更新裸克隆,但它对我不起作用。为了更新裸存储库(我认为 Let_Me_Be 是在问这个问题),我必须创建一个镜像存储库:
git clone --mirror <remote_repo>
Then I could run the following command in the mirrored repository to grab the main repository's updates:
然后我可以在镜像存储库中运行以下命令来获取主存储库的更新:
git fetch --all
I came across this solution by reading Mirror a Git Repository By Pulling
我通过阅读Mirror a Git Repository By Pulling发现了这个解决方案
回答by Colin D Bennett
The only solution besides recreating with git clone --mirror
is from Gregor:
除了重新创建之外,唯一的解决方案git clone --mirror
是来自 Gregor:
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
then you can git fetch
and you'll see the updates. The weird thing is that before this, even though there is a remote
configured, it has no branches listed in git branch -a
.
然后你可以git fetch
,你会看到更新。奇怪的是,在此之前,即使有remote
配置,它也没有列出git branch -a
.
回答by antak
Assuming:
假设:
$ git clone --bare https://github.com/.../foo.git
Fetch with:
获取:
$ git --git-dir=foo.git fetch origin +refs/heads/*:refs/heads/* --prune
Note: --git-dir=foo.git
is not required if you cd
to the directory first.
注意:--git-dir=foo.git
如果您cd
先进入目录,则不需要。
回答by simonvc
After much messing around I've found that this works for me.
经过一番折腾,我发现这对我有用。
Once:
一次:
git clone --mirror ssh://[email protected]:2000/repo
git remote add remote_site ssh://git@remote_site.address/repo
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
Everytime I want to sync:
每次我想同步时:
cd /home/myhome/repo.git
git --bare fetch ssh://[email protected]:2000/repo
git fetch ssh://[email protected]:2000/repo
git push --mirror remote_site
回答by Philipp
Add the bare repository as a remote repository, then use git push
.
将裸仓库添加为远程仓库,然后使用git push
.
回答by Alexander Samoylov
For me this combination worked:
对我来说,这种组合有效:
git remote add remote_site https://github.com/project/repo.git
git fetch -u remote_site +refs/heads/:refs/heads/*
git push --mirror
-u parameter for fetch was necessary, otherwise I get the error message: "Refusing to fetch into current branch refs/heads/master of non-bare repository" (see also https://stackoverflow.com/a/19205680/4807875)
-u 获取参数是必需的,否则我会收到错误消息:“拒绝获取到当前分支 refs/heads/master of non-bare repository”(另请参见https://stackoverflow.com/a/19205680/4807875)