![](/img/trans.png)
[英]Is it possible to maintain two local Git repositories with entirely different content, but push them to the same remote repository?
[英]How to setup git config for pushing to two different remote repositories from the same local repository?
过去几周我一直在使用 bitbucket 上的存储库进行一个项目。 最近,我决定我也想要我的 github 帐户上的存储库。 我已经成功设置了它,因此每次推送时,我都会推送到两个存储库。 github 存储库本质上是我对 bitbucket 存储库提交的精确副本。 我的问题是每次推送时我都必须为两个帐户输入我的姓名和用户名。
我研究了使用不同帐户的新条件包含,但似乎只有当存储库具有不同的文件路径时才有效,在这种情况下它们没有。
有谁知道设置我的 .git/config 文件的方法,以便它根据推送到的存储库自动使用特定的名称/电子邮件组合?
您可以将 2 个来源添加到您的项目中,如下所示
git remote add origin origin_url.git
git remote add origin2 origin_url.git
每次对代码库进行更改后,使用 git commit -m "commit message"
然后推送到两个仓库,
git push origin master
git push origin2 master
这每次都会推送到您的两个存储库。
您的问题已在此处得到解答: Git:在一个命令中推送到两个存储库
所以基本上你必须添加额外的存储库
git remote set-url --add --push origin git@github.com:TEST/REPO.git
(或者您可以使用 https 而不是 ssh)。 现在您已准备好通过以下方式推送到两个存储库
git push origin
如果您使用的是 Bitbucket 或 Gitlab,它们还会为您提供镜像存储库(取决于您的帐户类型)。 在 Bitbucket 中,还有很多插件可以镜像 GitHub 存储库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.