UINOTE

git 推送到多个远程仓库

将代码提交到多个仓库可以增加代码的安全性和使用的便利,那么如何将同一个仓库提交到多个远程仓库呢?


例如我有下面两个仓库:

https://git.crogram.com/doudoudzj/codes.git

https://github.com/doudoudzj/codes.git


看步骤:
一、添加第一个仓库

git remote add origin https://git.crogram.com/doudoudzj/codes.git


二、添加第二个仓库

git remote set-url --add origin https://github.com/doudoudzj/codes.git

如果还有其他仓库,则可以像添加第二个一样继续添加其他仓库

三、使用下面命令提交

git push origin --all


查看下编辑配置文件 .git/config 如下:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://git.crogram.com/doudoudzj/codes.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = https://github.com/doudoudzj/codes.git
[branch "master"]
	remote = origin
	merge = refs/heads/master

其实就是增加了一条 url 配置

那么,我们可以直接编辑配置文件,有多少个远程仓库,就在配置中添加多少个 url 就行了

上一篇:git 推送tag到远程仓库

下一篇:GitHub 宣布创建私有仓库免费且无限制