情形:有两个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. PHP AOP编程思想

    AOP思想(面向切面编程) 在应用开发中,我们经常发现需要很多功能,这些功能需要经常被分散在代码中的多个点上,但是这些点事实上跟实际业务没有任何关联.比如,在执行一些特殊任务之前需要确保用户是在登陆状 ...

  2. Animator Override Controller学习及性能测试

    本文由博主(YinaPan)原创,转载请注明出处: http://www.cnblogs.com/xsln/p/Animator_Override_Controller.html 一.Animator ...

  3. Javascript异步执行时要小心的变量作用域

    function asyncFunction(callback){ setTimeout(function(){ callback() },200); } var color = 'blue'; // ...

  4. POJ3009:Curling 2.0(dfs)

    http://poj.org/problem?id=3009 Description On Planet MM-21, after their Olympic games this year, cur ...

  5. SDUTOJ2465:其实玩游戏也得学程序(bfs+优先队列+回溯)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2465 题目描述 由于前两次的打击,ZYJ同学不 ...

  6. [LeetCode] 298. Binary Tree Longest Consecutive Sequence_Medium tag: DFS recursive

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. 机器学习理论基础学习9--- EM 算法

    EM算法的适用场景: EM算法用于估计含有隐变量的概率模型参数的极大似然估计,或者极大后验概率估计. 当概率模型既含有观测值,又含有隐变量或潜在变量时,就可以使用EM算法来求解概率模型的参数. 当概率 ...

  8. unity3d-碰撞检测

    碰撞检测 游戏中很多时候都要判断碰撞检测,比如子弹打中敌机.当碰撞后.就要发生爆炸. 或者敌机减血, 我们先看一张图片,看皮球从天空下落.与地面碰撞的过程 碰撞检测条件 游戏中两个对象发生碰撞是需要条 ...

  9. A+B+C问题

    这是一个非常简单的题目,意在考察你编程的基础能力.千万别想难了哦.输入为一行,包括了用空格分隔的三个整数 AA.BB.CC(数据范围均在-40−40 ~ 4040 之间).输出为一行,为“A+B+CA ...

  10. dedecms开启报错

    php.ini里面设置display_errors = On 开启错误提示,error_reporting = E_ALL & ~E_NOTICE 设置错误等级.也可以在php文件中ini_s ...