Git 同时与多个远程库互相同步
情形:有两个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 同时与多个远程库互相同步的更多相关文章
- git —— 多人协作(远程库操作)
1.查看远程库信息 $ git remote 2.查看详细远程库信息 $ git remote -v 3.推送分支 $ git push origin 分支名 4.抓取分支 $ git checkou ...
- git学习(4)远程库和分支管理
git学习(4)远程库和分支管理 1.1建立本地git库和远程库联系 我使用的是GitHub上的库,首先在GitHub上新建一个库,在建立与远程库的联系之前需要建立ssh key.建立ssh key可 ...
- Linux下安装git本地库与服务器端远程库
1. git是一个分布式版本管理系统,关于该工具的详细介绍,我认为廖雪峰老师介绍的非常全面:https://www.liaoxuefeng.com/wiki/896043488029600. 不 ...
- Git使用教程之从远程库克隆项目(四)
我们接下来在本地新建一个文件夹,把刚刚github上创建的项目克隆下来,操作步骤如下: 1.克隆项目: 找到github上面的SSH地址,如图: 开始克隆: $ git clone git@githu ...
- git 本地库推送远程库 版本冲突的解决方法
参考: http://blog.csdn.net/shiren1118/article/details/7761203 github上的版本和本地版本冲突的解决方法 $ git push XXX ma ...
- 【Git的基本操作十】远程库分支操作
远程库分支操作 1. 推送分支 在本地库新建分支 git branch [新分支名] 如创建一个develop分支: git branch develop 推送分支(将新分支发布在github上) g ...
- 3. git命令行操作之远程库操作
3.1 基本操作 注册GitHub账号 在本地创建一个本地库并初始化 登录到gitHub创建一个远程库 注意:windows的凭据管理器中会保存github登录信息.如果要切换登录者,先删除相应凭据 ...
- git 本地回滚与远程库回滚
不说废话,开始: 一.本地回滚: git reset --hard commit-id //回滚到commit-id 二.远程回滚操作分3步:①将本地分支退回到某个commit ②删除远程分支 ...
- Git 基础教程 之 从远程库克隆
③ 克隆一个本地仓库 a, 在合适的地方,在Git Bash下执行命令: git clone git@github.com:hardy9sap/gittutorial.git
随机推荐
- Ucenter社区服务搭建
1.搭建lamp环境yum –y install httpd php php-mysql mysql mysql-server 2启动服务 3.设置服务开机自动启动 4.上传UCEN ...
- 网络密钥交换协议——Diffie-Hellman
Diffie-Hellman算法是一种交换密钥的算法. 它是眼下比較经常使用的密钥交换算法. 这样的算法的优点是能让两台计算机在不安全的网络环境中完毕密钥的交换. 下面是整个算法的过程.当中红色字体表 ...
- Unity 脚本的执行顺序
在Unity脚本中常用到的函数就是下面这些,他们的顺序也是按照箭头的方向执行的. Awake ->OnEable-> Start -> FixedUpdate-> Update ...
- mysql查看和修改注释
MySQL查看注释,MySQL修改注释,mysql查看注释,mysql修改注释 1.给大家做演示,这里随便创建一张学生表,代码如下: CREATE TABLE `student` ( `id` int ...
- qsv转mp4
1:下载格式工厂:http://rj.baidu.com/soft/detail/13052.html?ald 2:安装 :选择安装位置,把不需要安装的软件前面的对号去掉. 3:下一步,把不需要的软件 ...
- [py][mx]django课程页显示city和机构封面图
city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...
- Java 7代码层面上的更新
Java 7已经完成的7大新功能: 1 对集合类的语言支持: 2 自动资源管理: 3 改进的通用实例创建类型推断: 4 数字字面量下划线支持: ...
- Integer类之成员变量
一.一共11个成员变量. 二.详情介绍. 1.value值.这个是Integer类的唯一标志.最重要的实例属性. 2.最小值和最大值常量.注意,计算机里面是以补码形式保存的,因此用十六进制时,给的数据 ...
- 《User Modeling with Neural Network for Review Rating Prediction》评论打分预测
摘要: 传统的评分预测只考虑到了文本信息,没有考虑到用户的信息,因为同一个词 在不同的用户表达中是不一样的.同样good 一词, 有人觉得5分是good 有人觉得4分是good.但是传统的文本向量表达 ...
- transition和animation区别
Transform:对元素进行变形: Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束. Animation:对元素某个 ...