Git:我可以在存储库中存储已知的存储库吗?

发布于 2024-09-02 16:30:19 字数 265 浏览 2 评论 0原文

我正在设置一个 Git 存储库。我知道您可以使用 git config --global 添加存储库,但是有没有办法让用户克隆这些已知的存储库?

目标是一旦用户克隆了存储库,他们就可以仅通过别名推送到其他存储库。

例如,我将 git://X/mobility.git 作为 X 添加到存储库中(以某种方式),用户从 git://Y 克隆它,但随后可以执行 git push X 而无需之前进行git配置

怎么做呢?

I am setting up a Git repository. I know you can add repositories using git config --global, but is there a way that those known repositories gets cloned by users?

The goal would be that once the repo gets cloned by userz, they can push to other repos just by their aliases.

For example, I add git://X/mobility.git as X to the repo (somehow), a user clone it from git://Y, but then can do git push X without previously doing the git config.

How to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木槿暧夏七纪年 2024-09-09 16:30:19

我不相信 Git 支持这一点。存储库别名对于本地计算机而言是单独的,不是克隆过程的一部分。

I don't believe Git supports this. Repository aliases are individual to the local machine and not part of the cloning process.

空城旧梦 2024-09-09 16:30:19

琥珀是对的。远程条目的配置不会与存储库的其余部分一起克隆(也不会任何其他存储库特定的配置数据)。

您可能会考虑(在存储库的跟踪内容中)包含一个脚本来设置遥控器。最终用户可以运行此脚本来创建遥控器。然而,该脚本不能自动运行,因为它会引入安全问题(克隆存储库应该是一个安全的操作;如果 Git 自动运行刚刚下载的某些脚本/二进制文件,则这不是一个安全的操作)。

顺便说一句,使用 git remote 来管理遥控器可能比使用 git config 更容易。

add_or_update() {
    if git config remote."$1".url >/dev/null 2>&1; then
        git remote set-url "$1" "$2"
    else
        git remote add "$1" "$2"
    fi
}
add_or_update foo [email protected]:foo.git
add_or_update add bar git://other.example.com/dev/bar.git

如果您使用非标准的 fetch refspec,您可能需要使用 git config,因为 git remote(尚)不支持管理远程的 refspec。

Amber is right. The configuration of remote entries is not cloned along with the rest of the repository (nor is any other repository specific configuration data).

You might consider including (in the tracked content of the repository) a script to setup the remotes. End users could run this script to create the remotes. The script can not, however be run automatically since it would introduce security problems (cloning a repository should be a safe operation; it would not be a safe operation if Git automatically ran some script/binary that it just downloaded).

Incidentally, it might be easier using git remote to manage the remotes instead of git config.

add_or_update() {
    if git config remote."$1".url >/dev/null 2>&1; then
        git remote set-url "$1" "$2"
    else
        git remote add "$1" "$2"
    fi
}
add_or_update foo [email protected]:foo.git
add_or_update add bar git://other.example.com/dev/bar.git

If you are using a non-standard fetch refspec, you may need to use git config, since git remote does not (yet) support managing a remote's refspec(s).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文