适合场景:
一个git项目需要能同时使用两个或多个远程仓库,比如GitHub+码云或者更多。
在项目的根目录查看git配置文件,一般是这样的:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://git.xpro.net/code1/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
1. 添加一个远程仓库
修改config文件,新增另一个远程仓库,并命名,譬如mayun:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://git.xpro.com/code1/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "mayun"]
url = https://gitee.com/code1/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
remote = mayun
merge = refs/heads/master
2. pull操作
使用以下命令,可以分别从两个远程仓库pull:
git pull origin master
git pull mayun master
如果出现 refusing to merge unrelated histories,那么加上"--allow-unrelated-histories"
git pull mayun master --allow-unrelated-histories
3. push操作
使用以下命令,可以分别push到两个远程仓库:
git push origin master
git push mayun master