情形:有两个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 -v
github 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 push
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To https://gitee.com/hongdada/learngit.git
a48d040..875d588 master -> master D:\代码\Git\learngit
λ git push gitosc master
Everything up-to-date D:\代码\Git\learngit
λ git push github master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
remote: Resolving deltas: % (/), completed with local object.
To https://github.com/hongdada/learngit.git
a48d040..875d588 master -> master

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

如果一次性推送呢

方法一:

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

推送:

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

看到有2个推送说明

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

[core]
repositoryformatversion =
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 =
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 =
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[branch "master"]
[branch "dev"]

修改配置文件为:

[core]
repositoryformatversion =
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 --all
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To https://github.com/hongdada/learngit.git
48a0880..2dab796 master -> master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To https://gitee.com/hongdada/learngit.git
48a0880..2dab796 master -> master

http://blog.csdn.net/isea533/article/details/41382699

Git 同时与多个远程库互相同步的更多相关文章

  1. git —— 多人协作(远程库操作)

    1.查看远程库信息 $ git remote 2.查看详细远程库信息 $ git remote -v 3.推送分支 $ git push origin 分支名 4.抓取分支 $ git checkou ...

  2. git学习(4)远程库和分支管理

    git学习(4)远程库和分支管理 1.1建立本地git库和远程库联系 我使用的是GitHub上的库,首先在GitHub上新建一个库,在建立与远程库的联系之前需要建立ssh key.建立ssh key可 ...

  3. Linux下安装git本地库与服务器端远程库

    1.    git是一个分布式版本管理系统,关于该工具的详细介绍,我认为廖雪峰老师介绍的非常全面:https://www.liaoxuefeng.com/wiki/896043488029600. 不 ...

  4. Git使用教程之从远程库克隆项目(四)

    我们接下来在本地新建一个文件夹,把刚刚github上创建的项目克隆下来,操作步骤如下: 1.克隆项目: 找到github上面的SSH地址,如图: 开始克隆: $ git clone git@githu ...

  5. git 本地库推送远程库 版本冲突的解决方法

    参考: http://blog.csdn.net/shiren1118/article/details/7761203 github上的版本和本地版本冲突的解决方法 $ git push XXX ma ...

  6. 【Git的基本操作十】远程库分支操作

    远程库分支操作 1. 推送分支 在本地库新建分支 git branch [新分支名] 如创建一个develop分支: git branch develop 推送分支(将新分支发布在github上) g ...

  7. 3. git命令行操作之远程库操作

    3.1 基本操作 注册GitHub账号 在本地创建一个本地库并初始化 登录到gitHub创建一个远程库 注意:windows的凭据管理器中会保存github登录信息.如果要切换登录者,先删除相应凭据 ...

  8. git 本地回滚与远程库回滚

    不说废话,开始: 一.本地回滚: git reset --hard commit-id //回滚到commit-id 二.远程回滚操作分3步:①将本地分支退回到某个commit    ②删除远程分支  ...

  9. Git 基础教程 之 从远程库克隆

    ③  克隆一个本地仓库 a, 在合适的地方,在Git Bash下执行命令:         git clone git@github.com:hardy9sap/gittutorial.git

随机推荐

  1. vue - 组件的创建

    组件的创建 vue的核心基础就是组件的使用,玩好了组件才能将前面学的基础更好的运用起来.组件的使用更使我们的项目解耦合.更加符合vue的设计思想MVVM. 那接下来就跟我看一下如何在一个Vue实例中使 ...

  2. 【python-opencv】20-图像金字塔

    知识点介绍 图像金字塔原理: 高斯金字塔 拉普拉斯金字塔: 代码层面知识点:  cv2.PyrDown:降采样  cv2.PyrUp:升采样 高斯金字塔与拉普拉斯金字塔 图像金字塔是图像中多尺度表达的 ...

  3. Python 标准输出 sys.stdout 重定向

    本文环境:Python 2.7 使用 print obj 而非 print(obj) 一些背景 sys.stdout 与 print 当我们在 Python 中打印对象调用 print obj 时候, ...

  4. NYOJ 275 队花的烦恼一

    队花的烦恼一 时间限制:3000 ms  |  内存限制:65535 KB 难度:1 描写叙述 ACM队的队花C小+常常抱怨:"C语言中的格式输出中有十六.十.八进制输出,然而却没有二进制输 ...

  5. [vue]vue双向绑定$on $emit sync-模态框

    双向绑定实现($on $emit) 关于父子之间数据更新同步, 如果单向绑定, 子修改了,父却没有修改, 这种一般不符合规范 正常更新数据的套路是: 1. 子通知父更新数据 2. 子自动刷新获取最新数 ...

  6. Summary: Deep Copy vs. Shallow Copy vs. Lazy Copy

    Object copy An object copy is an action in computing where a data object has its attributes copied t ...

  7. Fiddler过滤指定域名

    Fiddler过滤指定域名的方法一 切换到fiddler右侧窗口的Filters选项卡,勾选顶部的“Use Filters”,找到Hosts区域,设置以下三个选项: 1.第一项有三个选项,不做更改: ...

  8. 024-linux中动态库libXXX.so

    1.动态库的概念.动态链接库与普通的程序相比而言,没有main函数,是一系列函数的实现.通过shared和fPIC编译参数生产so动态链接库文件.程序在调用库函数时,只需要连接上这个库即可. 2.动态 ...

  9. Git 常用的命令

    基本内容: 工作区:就是你在电脑里能看到的目录. 暂存区:英文叫stage, 或index.一般存放在"git目录"下的index文件(.git/index)中,所以我们把暂存区有 ...

  10. python print 使用分隔符 或行尾符

    使用print() 函数输出数据,但是想改变默认的分隔符或者行尾符. >>> print('ACME', 50, 91.5) ACME 50 91.5 >>> pr ...