用例将远程分支推送到git中的另一个远程仓库

时间:2018-10-12 02:47:49

标签: git branch git-branch

在git中,我们可以像这样将一个远程分支推送到另一个远程:

> git clone git@foo1.com:a/a
> cd a
> git remote add other git@foo2.com:b/b
> git fetch --all
# ...
> git push origin other/master
Counting objects: 107, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (66/66), done.
Writing objects: 100% (107/107), 2.11 MiB | 0 bytes/s, done.
Total 107 (delta 52), reused 87 (delta 33)
remote: Resolving deltas: 100% (52/52), completed with 8 local objects.
To foo1.com:a/a
 * [new branch]        other/master -> other/master

因此在“ @ foo1.com:a / a”上,我们可以通过使用git branch -va命令将其获取为“ foo2.com:b/b”的远程地址:

* master                  7c6051f foo
  remotes/other/master    38a5a1b bar

如果我们仅使用git branch -v,则不会显示该远程分支。

但是我不认为这有什么用。我的本地人无法在foo1.com:a/a上与之互动,对吗?有人可以为此提供一个潜在的用例吗?

也可以通过某些git配置禁用它吗?

1 个答案:

答案 0 :(得分:0)

  

因此在“ @ foo1.com:a / a”上,我们可以通过使用git branch -va命令将其获取为“ foo2.com:b/b”的远程地址:

不,您不会:git branch -av纯粹是 local 命令,其中列出了在本地存储库中完成的本地分支。
您的远程仓库remotes/other/master中不存在该分支foo1.com:a/a。只有master是。

remotes/other/master是本地“远程跟踪分支”,用于您的本地仓库以记住分支“ other”从远程仓库“ master”推入或拉出的内容。

git push origin other/master

这确实会创建另一个名为other/master的分支到远程仓库originfoo1.com

但是您通常不需要:您在本地远程跟踪分支other/master与您自己的主服务器之间进行本地合并,然后用简单的master推动git push本身。

相关问题