博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git 同时与多个远程库互相同步
阅读量:6265 次
发布时间:2019-06-22

本文共 4283 字,大约阅读时间需要 14 分钟。

情形:有两个git服务器,比如github,gitosc,有个项目同时在两个服务器上,要互相同步

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

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

git remote rm origin

2:关联gitosc远程库

git remote add gitosc https://gitee.com/hongdada/learngit.git
git push -u gitosc master

关联github远程库

git remote add github https://github.com/hongdada/learngit.git
git push -u github master

3.查看远程库信息

λ git remote -vgithub  https://github.com/hongdada/learngit.git (fetch)github  https://github.com/hongdada/learngit.git (push)gitosc  https://gitee.com/hongdada/learngit.git (fetch)gitosc  https://gitee.com/hongdada/learngit.git (push)

这样就ok了,就布置好了,下面就是操作

D:\代码\Git\learngitλ git pushCounting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (2/2), 223 bytes | 0 bytes/s, done.Total 2 (delta 1), reused 0 (delta 0)To https://gitee.com/hongdada/learngit.git   a48d040..875d588  master -> masterD:\代码\Git\learngitλ git push gitosc masterEverything up-to-dateD:\代码\Git\learngitλ git push github masterCounting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (2/2), 223 bytes | 0 bytes/s, done.Total 2 (delta 1), reused 0 (delta 0)remote: Resolving deltas: 100% (1/1), completed with 1 local object.To https://github.com/hongdada/learngit.git   a48d040..875d588  master -> master

可以看出我第一次是直接git push,没有指定远程库名称,默认推送到了gitosc中,开始还以为一次性推送到了2个服务器呢,剩下的github需要指定名称推送。

如果一次性推送呢

方法一:

D:\代码\Git\learngitλ git remote  rm githubD:\代码\Git\learngitλ git remote rm gitoscD:\代码\Git\learngitλ git remote add all https://gitee.com/hongdada/learngit.gitD:\代码\Git\learngitλ git remote set-url --add all https://github.com/hongdada/learngit.git

推送:

D:\代码\Git\learngitλ git push all --allCounting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (2/2), 269 bytes | 0 bytes/s, done.Total 2 (delta 0), reused 0 (delta 0)To https://gitee.com/hongdada/learngit.git   af6a587..48a0880  master -> masterCounting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (2/2), 269 bytes | 0 bytes/s, done.Total 2 (delta 0), reused 0 (delta 0)To https://github.com/hongdada/learngit.git   af6a587..48a0880  master -> master

看到有2个推送说明

修改前打开项目.git文件夹内的config文件

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[branch "master"]    remote = gitosc    merge = refs/heads/master[branch "dev"][remote "github"]    url = https://github.com/hongdada/learngit.git    fetch = +refs/heads/*:refs/remotes/github/*[remote "gitosc"]    url = https://gitee.com/hongdada/learngit.git    fetch = +refs/heads/*:refs/remotes/gitosc/*

 修改后查看:

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[branch "master"][branch "dev"][remote "all"]    url = https://gitee.com/hongdada/learngit.git    fetch = +refs/heads/*:refs/remotes/all/*    url = https://github.com/hongdada/learngit.git

 方法二:根据上面的配置可以引出第二种一起修改多远程的方式,直接修改配置文件.git/config

删除all

git remote rm all

查看配置文件:

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[branch "master"][branch "dev"]

修改配置文件为:

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[branch "master"][branch "dev"][remote "all"]      url = https://github.com/hongdada/learngit.git     url = https://gitee.com/hongdada/learngit.git

推送信息:

D:\代码\Git\learngitλ git push all --allCounting objects: 3, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 290 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To https://github.com/hongdada/learngit.git   48a0880..2dab796  master -> masterCounting objects: 3, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 290 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To https://gitee.com/hongdada/learngit.git   48a0880..2dab796  master -> master

 

转载地址:http://icdpa.baihongyu.com/

你可能感兴趣的文章
otl使用存储过程或是LEFT JOIN时提示输出类型未知的问题
查看>>
集群(cluster)原理(转)
查看>>
小数格式:
查看>>
【MyBatis学习06】_parameter:解决There is no getter for property named in class java.lang.String...
查看>>
Eclipse导入别人的项目报错:Unable to load annotation processor factory 'xxxxx.jar' for project...
查看>>
与孩子一起学编程10章
查看>>
【再探backbone 03】博客园单页应用实例(提供源码)
查看>>
android 圆角编写(懒得去找,写给自己看的)
查看>>
chrome 搜索 jsonView
查看>>
chrome浏览器:chrome 69 恢复默认UI
查看>>
Irony - 一个 .NET 语言实现工具包
查看>>
Java之Static静态修饰符详解
查看>>
修改weblogic部署的应用名称
查看>>
aaronyang的百度地图API之LBS云与.NET开发 Javascript API 2.0【基本地图的操作】
查看>>
Java Nio 多线程网络下载
查看>>
C++不让程序一闪而过
查看>>
C# 中的枚举类型 enum (属于值类型)
查看>>
[Debug] Use Snippets to Store Behaviors in Chrome DevTools
查看>>
【Java面试题】3 Java的"=="和equals方法究竟有什么区别?简单解释,很清楚
查看>>
通用性好的win2003序列号: (推荐先用这个里面的)
查看>>