美文网首页
git提交代码到多个远程库

git提交代码到多个远程库

作者: 邱_sir | 来源:发表于2018-06-01 14:49 被阅读0次

所以需要在本地推送远程时同步到两个不同的git远程仓库

1.修改Config文件

在你的项目目录下找到.git文件夹,如果没有就需要查看显示隐藏文件了。 

然后找到里面的config文件 

一般正常情况下config里面的内容大概是这样婶儿的:

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

ignorecase = true

precomposeunicode = true

[remote "origin"]

url = git@gitee.com:qiuzhongwei0519/HaveCar--ww-2.0.git

fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

remote = origin

merge = refs/heads/master

这个时候我们需要修改它,让它有除了orgin之外的另外一个远程仓库 

可以取名为“mirror”即镜像仓库,我就把GitHub做为主要远程仓库,git@oschina做为国内镜像仓库 

于是修改后的config文件如下所示:

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

ignorecase = true

precomposeunicode = true

[remote "origin"]

url = git@gitee.com:qiuzhongwei0519/HaveCar--ww-2.0.git

fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

remote = origin

merge = refs/heads/master

这个时候我们需要修改它,让它有除了orgin之外的另外一个远程仓库 

可以取名为“mirror”即镜像仓库,我就把GitHub做为主要远程仓库,git@oschina做为国内镜像仓库 

于是修改后的config文件如下所示:

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

ignorecase = true

precomposeunicode = true

[remote "origin"]

url = git@gitee.com:qiuzhongwei0519/HaveCar--ww-2.0.git

fetch = +refs/heads/*:refs/remotes/origin/*

[remote "mirror"]

    url = git@git.oschina.net:hwangfantasy/beautify.git

    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

remote = origin

remote = mirror

merge = refs/heads/master

2. pull操作

使用以下命令,可以分别从两个远程仓库pull:

git pull origin master 

git pull mirror master

3. push操作

使用以下命令,可以分别push到两个远程仓库:

git push origin master 

git push mirror master

相关文章

网友评论

      本文标题:git提交代码到多个远程库

      本文链接:https://www.haomeiwen.com/subject/livxsftx.html