情形:有两个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. mysql全局唯一ID生成方案(二)

    MySQL数据表结构中,一般情况下,都会定义一个具有‘AUTO_INCREMENT’扩展属性的‘ID’字段,以确保数据表的每一条记录都可以用这个ID唯一确定: 随着数据的不断扩张,为了提高数据库查询性 ...

  2. mySql的普通索引和复合索引

    有关普通索引和组合索引问题: 索引分单列索引和组合索引:单列索引,即一个索引只包含单个列,一个表可以有多个单列索引,但这不是组合索引:组合索引,即一个索包含多个列.   MySQL索引类型包括:   ...

  3. LightOj 1248 - Dice (III)(几何分布+期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...

  4. Shell初学(一)hello world

    精简: 1.创建:可以使用 vi/vim 命令来创建文件如: test.sh   ,扩展名并不影响脚本执行,写什么都可以. 2.hello_world: #!/bin/bash            ...

  5. Rufus 制作 USB 启动盘简单教程

    制作 Windows 10 启动盘 U盘 / USB 安装盘图文教程  http://rufus.akeo.ie/downloads/rufus-2.2p.exe 1.将U盘连接到电脑,以管理员身份运 ...

  6. 万恶之源 - Python基础知识补充

    编码转换 编码回顾: 1. ASCII : 最早的编码. ⾥⾯有英⽂⼤写字⺟, ⼩写字⺟, 数字, ⼀些特殊字符. 没有中⽂, 8个01代码, 8个bit, 1个byte 2. GBK: 中⽂国标码, ...

  7. [py]python的私有变量

    参考 python中并没有真正意义上的私有成员,它提供了在成员前面添加双下划线的方法来模拟类似功能.具体来说: _xxx 表示模块级别的私有变量或函数 __xxx 表示类的私有变量或函数 这被称为na ...

  8. 实习培训——Java基础(2)

    实习培训——Java基础(2) 1  Java 变量类型 在Java语言中,所有的变量在使用前必须声明.声明变量的基本格式如下: type identifier [ = value][, identi ...

  9. KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2772)

    #include <stdio.h>#include <string.h>#include <stdlib.h>char a[1000001],b[1000001] ...

  10. XMR恶意挖矿案例简析

    前言 数字货币因其技术去中性化和经济价值等属性,逐渐成为大众关注的焦点,同时通过恶意挖矿获取数字货币是黑灰色产业获取收益的重要途径.本文简析通过蜜罐获取的XMR恶意挖矿事件:攻击者通过爆破SSH获取系 ...