问题描述
我正在使用分散式工作流程(Central + Fork)。有时,我想快速转发我的分支上的所有远程分支,并使用中央存储库上对应分支的最新更改。我已经创建了我的中央存储库的第二个克隆,它只是一个裸机版本。使用单个 git push
命令,是否可以将所有分支推送到分支?我知道通配符可以用于推送,但是我一直无法使其工作。例如,我尝试过这样的做法(我在裸回购上有两个远程交易,'上游'和'起源';原点指向我的分叉,上游是中央回购:
git push origin refs / remotes / upstream / *:refs / heads / *
我仍然发现git的refspec令人困惑,特别是,我不确定命名空间是什么,我假定所有远程分支都存储在 将所有分支引用 从(截断为相关选项): 仅供参考,您的原始命令 所以我不知道你的情况出了什么问题。 给你, 所有Git repos在它们下共享相同的参考目录结构 (相对于本身)在 refs / heads / * $
$ git push< fork> --all
.git / refs / heads /
到另一个远端。
$ b 文档
您的原始命令应该已经工作
git push origin refs / remotes / upstream / *:refs / heads / *
Refspecs Explained
< source>:< destination>
.git / refs /
目录。
refs / heads /
下。 refs / remotes /< remote> /
下存储远程跟踪分支(相对于本身)。
其他引用也可以存储在 refs /
下,包括但不限于 refs / tags /
,但我不会详述这些细节。您还可以在 refs /
下创建您自己的参考目录;例如,GitHub在 refs / pulls /< request-number> /
下存储了对请求的请求。
冒号:
的每个引用都是相对的 / strong>转到由refspec的那一面代表的回购。假设冒号的每一边都在前面添加了repo。
为了说明目的,我将添加 [source] /
和 [destination] /
添加到下面的refspec示例中,尽管这实际上并不是它们的正确语法。 / p>
因此,例如,如果您想将本地分支推送到远程,您需要将它们 推送到远程的本地分支 即可。您可以使用像这样的refspec:
git push< remote> [source] / refs / heads / *:[destination] / refs / heads / *
在上面的情况下,您也可以省略:refs / heads / *
,因为省略:< destination>
会导致Git用< code>< source>
git push< remote> refs / heads / *
现在让我们说你想推动你的本地远程跟踪分支分配到名为 refs / special /
的远程特殊命名空间文件夹。然后你使用下面的代码:
git push< remote> \
[source] / refs / remotes /< pick-a-remote> / *:[destination] / refs / special / *
I'm using the decentralized workflow (Central + Fork). On occasion, I'd like to fast-forward all of my remote branches on my fork with the latest changes from their corresponding branches on the central repository.
I've created a second clone of my central repository that is just a bare version. With a single git push
command, is it possible to push all branches to the fork? I know wildcards can be used in push, but I haven't been able to get it to work. For example, I tried this (I have two remotes on my bare repo, 'upstream' and 'origin'; origin points to my fork, and upstream is the central repo:
git push origin refs/remotes/upstream/*:refs/heads/*
I still find git's refspec confusing. Specifically, I'm not sure what namespaces are for what. I'm assuming all remote branches are stored under refs/heads/*
.
Simply use
git push <fork> --all
to push all branch references under .git/refs/heads/
to the other remote.
Documentation
From the git-scm documentation for git push
(truncated to relevant options):
Your Original Command Should Have Worked
FYI, your original command
git push origin refs/remotes/upstream/*:refs/heads/*
should have worked as well, so I'm not sure what went wrong in your case.
Refspecs Explained
According to you,
So here's the deal with refspecs of the form
<source>:<destination>
All Git repos share the same reference directory structure under their
.git/refs/
directory.Every repo stores local branches (relative to itself) under
refs/heads/
.Every repo stores remote-tracking branches (relative to itself) under
refs/remotes/<remote>/
.Other references can also be stored under
refs/
, including, but not limited to,refs/tags/
, but I won't go into details about those. You can also create your own reference directories underrefs/
; GitHub, for example, stores pull requests on remotes underrefs/pulls/<request-number>/
.
References on each side of the colon
:
are relative to the repo represented by that side of the refspec. Pretend that each side of the colon is prepended with the repo on that side.For illustration purposes, I'll add
[source]/
and[destination]/
to the refspec examples below, even though that that's not actually the correct syntax for them.So, for example, if you wanted to push your local branches to a remote, you need to push them to the remote's local branches. You can use a refspec like this:
git push <remote> [source]/refs/heads/*:[destination]/refs/heads/*
In the above case, you can also omit the
:refs/heads/*
, since omitting:<destination>
causes Git to replace that side with the same references used on the<source>
side:git push <remote> refs/heads/*
Now lets say that you wanted to push your local remote-tracking branches to a special "namespaced" folder on your remote called
refs/special/
. Then you use the following:git push <remote> \ [source]/refs/remotes/<pick-a-remote>/*:[destination]/refs/special/*
这篇关于如何推动裸露的回购分支机构到另一个远程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!