git - 将代码推送到多个源

标签 git githooks git-push

我想做一个git推送,并且更改应该推送到两个不同的源。有没有一种方法可以用 git 的一个命令推送到多个源?也许是一个不错的钩子(Hook)?

最佳答案

我使用了两种方法来做到这一点。当我有 fork 存储库和上游远程时,我发现一种方便的方法是在远程上使用 pushurl 配置选项。仅就起源而言,它看起来像这样:

[remote "origin"]
    url = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b5bba692b5bba6baa7b0fcb1bdbf" rel="noreferrer noopener nofollow">[email protected]</a>:user/repo.git
    pushurl = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f5fbe6d2f5fbe6fae7f0bcf1fdff" rel="noreferrer noopener nofollow">[email protected]</a>:user/repo.git
    pushurl = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e4eaf7c3e4eaf7ebf6e1ade0ecee" rel="noreferrer noopener nofollow">[email protected]</a>:me/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

对于 fork 存储库,我在上游远程中使用pushurl技巧,并将其推送到我的 fork 和上游存储库。它有助于保持主分支同步,无需大惊小怪。

我还在我的基础设施上托管的存储库上使用了接收后 Hook ,以将它们镜像到其他地方(例如 GitHub)。接收后 Hook 如下所示:

nohup git push --mirror <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="26414f5266414f524e53440845494b" rel="noreferrer noopener nofollow">[email protected]</a>:user/repo.git &> ~/.mirror.log

然后我推送到服务器上的存储库,然后服务器推送到 GitHub 克隆。您需要确保正确设置 SSH key ,但除此之外,这非常简单。

关于git - 将代码推送到多个源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13077081/

相关文章:

git - 如何为 Qualcomm MSM 系统编译 Android 4.4.2?

git - 您通常在 Git 预提交 Hook 中包含哪些脚本/调用?

Git钩子(Hook)自动安装

git - 为什么 merge 后的 git hook 没有运行?

Git 推送错误 : refusing to update checked out branch

Git:从远程 pull 但保留本地提交

git - 如何撤消最后一次 pull 并提交

python - 如何为基于 zip 的 CloudFunction 部署启用 cloudbuild.yaml?

git - 错误 : src refspec master does not match any

github - 错误: RPC failed; curl 55 The requested URL returned error: 401 when pushing to GIT from R Studio