@aqa510415008
2019-03-15T14:08:17.000000Z
字数 1498
阅读 1140
Git
场景:有两个git服务器,比如github,gitee,有个项目同时在两个服务器上,要互相同步。
其实命令还是比较简单的,比如一个现有的git项目,在github,gitee中分别创建好对应的项目。
$ git remote rm origin
$ git remote add github https://github.com/AClumsy/ASF.git
$ git push -u github master
$ git remote add gitee https://gitee.com/alingfly/ASF_Test.git
$ git push -u gitee master
在关联Gitee
出现报错,推送失败,原因Gitee库拒绝接收。
找到了一上午之后,发现需要强制上传,强制上传之后成功了。
$ git push -f gitee master
我们现在来测试一下,push
操作一下是否推送到两个库中。
$ git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 500 bytes | 500.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/AClumsy/ASF.git
f4b683b..7817902 master -> master
如果我没有指定任何库的情况下,git push
命令只会推送到 Github
库去,大概是因为我第一条远程库的关联是 github
,下面来试一下推送到指定库中。
命令:
$ git push gitee master
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 500 bytes | 500.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Powered By Gitee.com
To https://gitee.com/alingfly/ASF_Test.git
f4b683b..7817902 master -> master
从日志中可以看到推送到 Gitee
库成功了。
$ git remote -v
github https://github.com/AClumsy/ASF.git (fetch)
github https://github.com/AClumsy/ASF.git (push)
gitosc https://gitee.com/alingfly/ASF_Test.git (fetch)
gitosc https://gitee.com/alingfly/ASF_Test.git (push)