Git管理多个远程仓库(GitHub和Coding)

两个空代码仓库

如果是两个仓库都是空的,就直接在 .git/config 中添加远端地址

[remote "origin"]
    url = https://github.com/younglaker/octjs.git
    url = https://git.coding.net/laker/octjs.git  #添加新地址
    fetch = +refs/heads/*:refs/remotes/origin/*

地址是配好了,但是还要注意分支一致。我这里都用master,就不会有问题。


非空代码仓库

假设Github中使用了一段时间,想在Coding里备份一个,要想把两边仓库同步到一致的状态。

线到Coding新建仓库,获得地址后, .git/config 中添加Coding的远端地址,这里我命名为coding:

[remote "origin"]
    url = https://github.com/younglaker/octjs.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[remote "coding"]   #添加coding远端
    url = https://git.coding.net/laker/octjs.git  #远端地址
    fetch = +refs/heads/*:refs/remotes/coding/*  #注意修改远端名

使用Git GUI 获取 Coding上的信息,你也可以使用命令行完成一下操作:

这里写图片描述

合并:
这里写图片描述

推送,记得选Coding远端:
这里写图片描述

然后再修改 .git/config ,吧Coding也用origin远端名,下次就只用 git push 就可以推送到两边了。重启 Git GUI 也只剩一个远端了:

[remote "origin"]
    url = https://github.com/younglaker/octjs.git
    url = https://git.coding.net/laker/octjs.git
    fetch = +refs/heads/*:refs/remotes/origin/*


Github 不为空,Coding为新建项目

那就在Coding新建项目时导入Github项目,本地git配置改为:

[remote "origin"]
    url = https://github.com/younglaker/octjs.git
    url = https://git.coding.net/laker/octjs.git
    fetch = +refs/heads/*:refs/remotes/origin/*
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值