码云一个仓库只有一个项目吗_一个项目push到多个远程Git仓库

我创建了一个项目,然后通过下面的命令 push 到了 GitHub 上。如何再将这个项目 push 到其他远程仓库呢?

git remote add github https://github.com/zxbetter/test.git

git push -u github master

方法一: 使用 git remote add 命令

1.1# 如下命令查看远程仓库的情况,可以看到只有一个叫 github 的远程仓库。

git remote

github

git remote -v

github https://github.com/zxbetter/test.git (fetch)

github https://github.com/zxbetter/test.git (push)

1.2# 使用如下命令再添加一个远程仓库(这里以码云为例)

git remote add oschina https://git.oschina.net/zxbetter/test.git

1.3# 再次查看远程仓库的情况,可以看到已经有两个远程仓库了。然后再使用相应的命令 push 到对应的仓库就行了。这种方法的缺点是每次要 push 两次。

git remote

github

oschina

git remote -v

github https://github.com/zxbetter/test.git (fetch)

github https://github.com/zxbetter/test.git (push)

oschina https://git.oschina.net/zxbetter/test.git (fetch)

oschina https://git.oschina.net/zxbetter/test.git (push)

方法二: 使用 git remote set-url 命令

2.1# 删除方法一的 oschina 远程仓库。

git remote rm oschina

2.2# 使用如下命令添加远程仓库。

git remote set-url --add github https://git.oschina.net/zxbetter/test.git

2.3# 查看远程仓库情况。可以看到 github 远程仓库有两个 push 地址。这种方法的好处是每次只需要 push 一次就行了。

git remote -v

github https://github.com/zxbetter/test.git (fetch)

github https://github.com/zxbetter/test.git (push)

github https://git.oschina.net/zxbetter/test.git (push)

方法三: 修改配置文件

打开 .git/config 找到 [remote "github"],添加对应的 url 即可,效果如下。这种方法其实和方法二是一样的。

[remote "github"]

url = https://github.com/zxbetter/test.git

fetch = +refs/heads/*:refs/remotes/github/*

url = https://git.oschina.net/zxbetter/test.git

关于 git pull

方法二和三在 push 的时候比较方便。但是在 pull 的时候只能从方法三中的第一个 url 地址拉取代码。而方法一则不存在这种问题(可能要解决冲突)。

所以,如果只进行 push 操作,推荐方法二和三,如果也要进行 pull 操作,推荐方法一。

参考

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值