在已经习惯使用git同步写代码,github无疑是最的托管平台,但是国内由于“你懂的”原因,速度很慢,有时无法访问,于是想把自己的代码同步到多个不同的远程仓库备份。

我的主要仓库:

[github] https://github.com/wonux/test.git 主仓库

[oschina] https://git.oschina.net/wonux/test.git 国内常用仓库

另外,国内还有coding(原来的gitcafe合并到了coding),csdn code等。

添加同名多远程仓库

添加一个remote,这里是all,也可以是别的名字(如origin)

git remote add all https://github.com/wonux.test.git

再添加另一个:

git remote set-url --add all https://git.oschina.net/wonux/test.git

重复向同一个远程仓库名字添加需要set-url --add参数

如果有多个,按照上面这一个命令进行添加.

向多远程仓库推送代码

git push all --all

这样就会一次提交到多个库了,上面命令输出如下:

git push all --all
Username for 'https://github.com': wonux
Password for 'https://wonux@github.com':
Counting objects: 68, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (56/56), done.
Writing objects: 100% (68/68), 72.16 KiB | 0 bytes/s, done.
Total 68 (delta 13), reused 0 (delta 0)
To https://github.com/wonux/test.git
* [new branch] master -> master
Username for 'https://git.oschina.net': wonux
Password for 'https://wonux@git.oschina.net':
Counting objects: 68, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (56/56), done.
Writing objects: 100% (68/68), 72.16 KiB | 0 bytes/s, done.
Total 68 (delta 13), reused 0 (delta 0)
To https://git.oschina.net/wonux/test.git
* [new branch] master -> master

记住不要忘记--all参数,如果不加--all,则无法推送,提示:

git push all
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name. Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch. See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git) fatal: unable to access 'https://github.com/wonux/test.git/': Couldn't resolve host 'github.com'

分析配置文件

在操作完上面的添加命令后,如果我们打开.git/config文件,我们可以看到这样的配置:

[remote "all"]
url = https://github.com/wonux/test.git
fetch = +refs/heads/*:refs/remotes/all/*
url = https://git.oschina.net/wonux/test.git

因此,直接在.git/config文件中添加:

[remote "all"]
url = https://github.com/wonux/test.git
fetch = +refs/heads/*:refs/remotes/all/*
url = ……

有多少个远程库,就配置多少个url即可.

从这里可以看出,第一种方法生成的配置中还有一个fetch配置,这个配置可以完全去掉.

Git提交到多个远程仓库的更多相关文章

  1. Git提交到多个远程仓库(多看两个文档)

    Git提交到多个远程仓库(多看两个文档) 一.总结 一句话总结: 二. Git提交到多个远程仓库(多看两个文档) 有两种做法,先看第一种 一.通过命令行进行操作 例如我有下面两个仓库: Mybatis ...

  2. git提交本地文件到远程仓库及参与的项目仓库

    1.git提交本地文件到组织 1.先再组织中建立个用于存放文件的仓库建然后复制仓库地址: 2.进入要上传的文件的根目录下右击 git Bash 进入git控制台,我要上传的文件如下: 3.进入后: 1 ...

  3. git将代码提交到多个远程仓库

    在项目目录下执行: git remote set-url --add origin http://mayun.cn/xxx/adsdsdsdcelery-demo.git 即可添加一个远程仓库. 再执 ...

  4. 初谈Git(本机克隆项目远程仓库)

    1. 码云注册与新建项目 注册并新建项目 2. Git安装并配置 安装 配置 3. clone项目 附:一些Git命令 git clone 拷贝并跟踪远程的master分支 git add 跟踪新文件 ...

  5. git提交本地分支到远程分支

    git提交本地分支到远程分支   git 常用命令(含删除文件) Git常用操作命令收集: 1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/j ...

  6. Git 学习(五)远程仓库

    Git 学习(五)远程仓库 之前的章节所说的是本地Git仓库的操作,版本管理的优越性显然不会仅仅在本地.远程仓库也就是服务器或是网络端的仓库操作也是必须的. 本文具体说明 Git 的远程仓库操作,示例 ...

  7. Android基础新手教程——1.5.2 Git之使用GitHub搭建远程仓库

    Android基础新手教程--1.5.2 Git之使用GitHub搭建远程仓库 标签(空格分隔): Android基础新手教程 本节引言: 在上一节中.我们学习了怎样使用Git.构建我们的本地仓库.轻 ...

  8. Git同时提交到多个远程仓库

    使用git同时提交到多个远程库的操作方式为: 比如我需要你将同一份代码提交到如下的两个库中: https://gitee.com/FelixBinCloud/recruit.git https://g ...

  9. Git操作_从github远程仓库克隆到本地仓库, 本地代码提交

    实现目的: 从github远程仓库克隆到本地仓库:本地代码提交到远程仓库. 一.从github远程仓库克隆到本地仓库: 命令行切换到指定的仓库想存放的目录,执行如下命令:git clone  远程仓库 ...

随机推荐

  1. 《剑指Offer》面试题-从头到尾打印链表

    题目描述: 输入一个链表,从尾到头打印链表每个节点的值. 输入: 每个输入文件仅包含一组测试样例.每一组测试案例包含多行,每行一个大于0的整数,代表一个链表的节点.第一行是链表第一个节点的值,依次类推 ...

  2. DOM(二) 判断节点包含关系

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. IP 首部检验和算法

    原创博文,转载请注明出处. 在学习TCP/IP 详解的过程中遇到了不止一次的关于检验和的概念,在吸取了他人理解的前提下,我决定用Wireshark 进行抓包分析. 首先我们得知道IP数据包格式 首先把 ...

  4. c#winform关闭窗口时触发的事件

    用户关闭软件时,软件一般会给“是否确认关闭”的提示. 通常,我们把它写在FormClosing 事件中,如果确定关闭,就关闭:否则把FormClosingEventArgs 的 Cancel 属性设置 ...

  5. Task.WhileAll扩展方法

    TPL实现Task.WhileAll扩展方法 文章翻译整理自 Nikola Malovic 两篇博文: Task.WhileAll Awaitable task progress reporting ...

  6. [原]调试没有符号的 iOS 应用

    说明: 这里的调试是指使用 lldb 远程调试 iOS 应用 设置断点是指在 ObjC 方法上设置断点 使用场景: 1.调试被 strip 了的 iOS 应用 2.调试被 strip 了的 iOS 系 ...

  7. 新版C#编译器关于函数闭包

    新版C#编译器关于函数闭包的一处更改   在Visual Basic.NET中,如果你写下类似下面的代码: Public Sub Test() For i = 0 To 100 Dim func =  ...

  8. C#基础之方法和参数

    C#基础之方法和参数 接上一篇<C#基础之类型和成员基础以及常量.字段.属性> 实例方法.静态方法 C#中的方法分为两类,一种是属于对象(类型的实例)的,称之为实例方法,另一种是属于类型的 ...

  9. 简洁AngularJS框架后台管理系统bootstrap后台模板

    最近在做一个后台管理的项目,但是没有设计图完全,所以就发现一款非常不错的模版. 这个模版是基于 AngularJS 和 bootstrap 的后台管理系统模版. Minovate是 AngularJS ...

  10. Android KeyLogger Demo

    @author: dlive 代码见github: https://github.com/Dliv3/Android-KeyLogger-Demo 前言 之前开发过一个Android的木马,其中Key ...