0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

为 git 同时添加两个远程仓库

Posted at


转自:http://giaogiaocat.github.io/tool/git-origin/

一直使用GitHub托管代码,但最近觉得下载速度太慢了。所以打算把仓库同步到 https://codeup.aliyun.com/ 上,下载的时候可以提高速度。

之前的操作

设定不同的remote,分别推送,感觉很麻烦

git remote add origin https://github.com/USERNAME/REPO1.git
git remote add gitee https://gitee.com/USERNAME/REPO2.git

git push origin master
git push gitee master

多地址的 remote repo

一般来说最佳方法是给 origin 设两个地址:

git remote set-url origin --add https://github.com/USERNAME/REPO1.git
git remote set-url origin --add https://github.com/USERNAME/REPO2.git

在 .git/config 里得到

...
[remote "origin"]
    url = https://USERNAME@github.com/USERNAME/REPO1.git
    url = https://USERNAME@github.com/USERNAME/REPO2.git
...
[branch "master"]
    remote = origin
...

然后 git push origin master 就会同时推送到两个 repo,而 git pull origin master 会从两个 repo 里取得更新。

当然 URL 和 repo 不一定非要是 GitHub 上的,具有两个 url 的 remote 也不一定要是 origin,比如可以设置成 all。

只用于 push 的备份 repo

你想从 repo1 pull,但是 push 的时候要推送到 repo1 和 repo2。

git remote set-url origin --add https://github.com/USERNAME/REPO1.git
git remote set-url origin --push --add https://example.com/USERNAME/REPO2.git

在 .git/config 里得到

...
[remote "origin"]
    url = https://USERNAME@github.com/USERNAME/REPO1.git
    pushurl = https://USERNAME@example.com/USERNAME/REPO2.git
...
[branch "master"]
    remote = origin
...

然后 git push origin master 就会同时提交到两个 repo,而 git pull origin master 只会从repo1 里取得更新。

码云 https://gitee.com/

如果码云导入的是github项目,会10分钟左右同步一次,你也可以点击同步按钮手动同步。


参考:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?