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
随机推荐
- 正则表达式(二):Unicode诸问题上篇(转)
原文:http://www.infoq.com/cn/news/2011/02/regular-expressions-unicode 关于正则表达式的文档很多,但大部分都是英文的,即便有中文的文档, ...
- maven项目创建
一.搭建步骤 ♦首先创建一个Maven的Project,如下图: ♦点击Next,勾选 Create a simple project ♦点击Next,注意Packing要选择war,因为我们创建的是 ...
- 【PHP】PHP初学者的学习线路
先来看下PHP初学者的学习线路: (1) 熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作简单的网页,对元素属性相对熟悉. (2) 理解动态语言的概念和运做机制,熟悉基本的PHP语法. ( ...
- 【Loadrunner】Error -26601: Decompression function 错误解决、27728报错解决方案
一. Error -26601: Decompression function 错误解决 Action2.c(30): Error -26601: Decompression function ...
- 配合dedecms内容模型实现后台输入栏目id前端输出文章列表
为了简化开发的工作量,也方便编辑快速操作,决定将后台进行重新设置.配合dedecms内容模型实现后台输入栏目id前端输出文章列表,这样制作科室专题页也变快了很多.比如,我们添加一个“科室专家栏目id” ...
- 启动InnoDB引擎的方法
启动InnoDB引擎的方法 http://down.chinaz.com/server/201207/2090_1.htm 启动InnoDB引擎的方法 Mysql中默认的是MyISAM数据引擎,可惜此 ...
- SQL 4
SQL WHERE 子句 WHERE 子句用于过滤记录. SQL WHERE 子句 WHERE 子句用于提取那些满足指定标准的记录. SQL WHERE 语法 SELECT column_name,c ...
- IP追踪
cmd里输入:tracert www.baidu.com 上图箭头方框中就是对应公司的总网IP
- 申请 Let’s Encrypt 泛域名证书 及 Nginx/Apache 证书配置
什么是 Let’s Encrypt? 部署 HTTPS 网站的时候需要证书,证书由 CA (Certificate Authority )机构签发,大部分传统 CA 机构签发证书是需要收费的,这不利于 ...
- Apache下设置网站目录的访问权限
禁止用户对某一个目录及目录下文件的访问,仅允许本地访问 <Directory "/wwwroot/cert/"> Require local </Director ...