[关闭]
@aqa510415008 2019-03-15T06:08:17.000000Z 字数 1498 阅读 1015

Git 多远程仓库互相同步

Git

场景:有两个git服务器,比如github,gitee,有个项目同时在两个服务器上,要互相同步。

其实命令还是比较简单的,比如一个现有的git项目,在github,gitee中分别创建好对应的项目。

1. 移除现在旧有的远程服务器

  1. $ git remote rm origin

2. 关联远程库

  1. $ git remote add github https://github.com/AClumsy/ASF.git
  2. $ git push -u github master
  3. $ git remote add gitee https://gitee.com/alingfly/ASF_Test.git
  4. $ git push -u gitee master

在关联Gitee出现报错,推送失败,原因Gitee库拒绝接收。

TIM截图20190314170518.png-11.2kB

找到了一上午之后,发现需要强制上传,强制上传之后成功了。

  1. $ git push -f gitee master

我们现在来测试一下,push 操作一下是否推送到两个库中。

  1. $ git push
  2. Enumerating objects: 9, done.
  3. Counting objects: 100% (9/9), done.
  4. Delta compression using up to 4 threads
  5. Compressing objects: 100% (5/5), done.
  6. Writing objects: 100% (5/5), 500 bytes | 500.00 KiB/s, done.
  7. Total 5 (delta 3), reused 0 (delta 0)
  8. remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
  9. To https://github.com/AClumsy/ASF.git
  10. f4b683b..7817902 master -> master

如果我没有指定任何库的情况下,git push 命令只会推送到 Github 库去,大概是因为我第一条远程库的关联是 github,下面来试一下推送到指定库中。
命令:

  1. $ git push gitee master
  2. Enumerating objects: 9, done.
  3. Counting objects: 100% (9/9), done.
  4. Delta compression using up to 4 threads
  5. Compressing objects: 100% (5/5), done.
  6. Writing objects: 100% (5/5), 500 bytes | 500.00 KiB/s, done.
  7. Total 5 (delta 3), reused 0 (delta 0)
  8. remote: Powered By Gitee.com
  9. To https://gitee.com/alingfly/ASF_Test.git
  10. f4b683b..7817902 master -> master

从日志中可以看到推送到 Gitee 库成功了。

3. 查看远程库信息

  1. $ git remote -v
  2. github https://github.com/AClumsy/ASF.git (fetch)
  3. github https://github.com/AClumsy/ASF.git (push)
  4. gitosc https://gitee.com/alingfly/ASF_Test.git (fetch)
  5. gitosc https://gitee.com/alingfly/ASF_Test.git (push)

4. 未完待续...

引用:https://www.cnblogs.com/hongdada/p/7573923.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注