git 一个项目如何同时使用Bitbucket和GitHub?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12961514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Bitbucket and GitHub at the same time for one project?
提问by erogol
I have one repository which I want to push into Bitbucket and GitHub. It is vital for my repository to be hosted by both.
我有一个要推送到 Bitbucket 和 GitHub 的存储库。我的存储库由两者托管至关重要。
Is there a way to do this in Git?
有没有办法在 Git 中做到这一点?
回答by Denis Kniazhev
You can use multiple remote repositories with git. But you'll have to push separately into 2 of your remotes I believe.
您可以通过 git 使用多个远程存储库。但是我相信您必须分别推入 2 个遥控器。
For example, if your project currently points to github, you can rename your current remote repository to github
:
例如,如果您的项目当前指向 github,则可以将当前的远程存储库重命名为github
:
$ git remote rename origin github
You can then add another remote repository, say bitbucket
:
然后您可以添加另一个远程存储库,例如bitbucket
:
$ git remote add bitbucket [email protected]:your_user/your_repo.git
Now in order to push changes to corresponding branch on github or bitbucket you can do this:
现在为了将更改推送到 github 或 bitbucket 上的相应分支,您可以执行以下操作:
$ git push github HEAD
$ git push bitbucket HEAD
Same rule applies to pulling: you need to specify which remote you want to pull from:
同样的规则适用于拉取:您需要指定要从哪个远程拉取:
$ git pull github your_branch
$ git pull bitbucket your_branch
回答by Kevin Lee
Yes, you can do that. You don't have to push twice but just once to push to both remote repositories. I had the same issue before so wrote how to do it here. Git: Push to / Pull from Both Github and Bitbucket
是的,你可以这样做。您不必推送两次,只需推送一次即可推送到两个远程存储库。我之前遇到过同样的问题,所以在这里写了如何做。 Git:从 Github 和 Bitbucket 推送到/拉取
回答by Ahmad Awais
A few EASYsolutions.
一些简单的解决方案。
Multiple remotes pushed (and fetched) independently
多个遥控器独立推送(和获取)
This is the easiest to get your head around, but the most effort to maintain.
这是最容易理解的方法,但最需要维护。
We start out by adding our new remote:
我们首先添加我们的新遥控器:
$ cd myproject
$ git remote add bitbucket ssh://[email protected]/user/myproject.git
$ git push bitbucket master
Straight forward no? Except of course every time we commit any changes, we need to push to both our original “origin” and our new remote “bitbucket”:
直接不?当然,除了每次我们提交任何更改时,我们都需要同时推送到我们的原始“源”和我们新的远程“bitbucket”:
$ git push origin master
$ git push bitbucket master
Not a massive overhead, but I'm sure it will grate over time. Or you can create an `alias gpob="git push origin master && git push bitbucket master".
不是一个巨大的开销,但我相信它会随着时间的推移而消失。或者你可以创建一个`alias gpob="git push origin master && git push bitbucket master"。
Single remote with multiple URLs pushed (and fetched) consecutively
具有连续推送(和获取)多个 URL 的单个遥控器
With this method, we are going to add an additional URL to our existing remote “origin”:
使用此方法,我们将向现有的远程“源”添加一个额外的 URL:
$ cd myproject
$ git remote set-url --add origin ssh://[email protected]/user/myproject.git
$ git push origin master
Everything up-to-date
Everything up-to-date
Much less effort!
少了很多努力!
Of course silver lining has a cloud, and in this case, it is that while we can push to multiple URLs simultaneously, we can only fetch from the original “origin” (you can change this, but that is out of scope for this post).
当然,一线希望是一团乌云,在这种情况下,虽然我们可以同时推送到多个 URL,但我们只能从原始“来源”中获取(您可以更改这一点,但这超出了本文的范围) )。
Finally, to see which remote will be fetched from:
最后,查看将从哪个遥控器获取:
$ git remote -v show
I blogged about itas well.
我也写了关于它的博客。