定义一个自定义的git remote

丹尼尔·斯蒂芬斯(Daniel Stephens)

我读了这篇著名的文章

在此处输入图片说明

我了解bobclair如何原点同步,但是我不了解alicebobdavidclair之间的联系

文章说:

[...]但是,除了集中的推拉关系外,每个开发人员还可以从其他同伴那里拉出变更以组成子团队。

从技术上讲,这仅意味着Alice定义了一个名为bob的Git遥控器,该遥控器指向Bob的存储库,反之亦然。

Do I understand it correctly that two teams (alice and david) sync from origin but created their own git server endpoint to make it accessible to bob and clair?

torek

In Git, a remote is a short name—well, as long as you like—that stands in for a URL. It does a little more than that, but that's its main initial job.

When you use git clone to make a Git repository, the git clone command adds one remote for you. The standard name for this one remote is origin. So most Git repositories have exactly one remote, named origin.

To add another remote, use:

git remote add

which takes two required parameters:

  • the name of the remote to add, and
  • the URL.

To see the URL attached to some repository, use git remote -v or git config --get remote.name.url:

$ git remote -v
origin  ssh://[email protected]/path/to/repo.git (fetch)
origin  ssh://[email protected]/path/to/repo.git (push)
$ git config --get remote.origin.url
ssh://[email protected]/path/to/repo.git

The git remote command reveals that each remote can in fact store two URLs. The primary one, under .url, is used for both git fetch and git push by default. If you set a second one using remote.name.pushurl, that one is used for git push, while the main one is used for git fetch.

If Alice is frequently going to fetch from Bob, she might do:

git remote add bob <url>

The URL here can be an ssh:// URL, a git:// URL, an https:// URL, or a file:// URL, or it can just be a local path (some folks use this sort of thing with network-shared drives or VMs). Be aware that when using local paths, Git makes file system specific assumptions, if it can, that can result in weirdness when using network-shared drives and the like. When using file:// URLs, Git makes copies, so that if the network goes down you can still work locally.

Once you have a remote, git fetch to that remote will obtain their branch names, and copy their commits into your repository accordingly. So Alice would typically end up with bob/master, and maybe bob/feature if Bob has a branch named feature. But you can set additional settings under these various remote names. Alice could configure her bob remote to pick up only some selected set of Bob's branch names, for instance.

一旦拥有多个遥控器,git fetch没有参数就变得很有趣。如果你只有一个遥控器,命名origingit fetch总是在你的短名的URL获取origin如果您有两个或更多,则git fetch使用哪个遥控器答案在文档中; 请参阅说明部分。

请注意,表示从所有远程获取--all选项除非您定义了多个遥控器,否则永远没有任何理由要使用git fetchgit fetch --all

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章