git向多个远程库提交代码

在公司搭了套gerrit进行代码管理,又想将代码同步到csdn上,所以就需要将一份代码提交到两个不同的远程仓库。具体操作步骤如下。

1、 将gerrit上的代码clone到本地。

git clone ssh://[email protected]:29418/iProbe_v2

2、 修改工程目录下的.git/config文件,添加远程仓库

原文件内容为:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://[email protected]:29418/iProbe_v2
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

添加后的文件内容为:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://[email protected]:29418/iProbe_v2
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "csdn"]
    url = [email protected]:superbfly/iprobe_v2.git
    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
remote = origin
remote = csdn
merge = refs/heads/master

注:红色为添加的内容

3、使用git remote -v 命令查看远程仓库结果如下:

csdn [email protected]:superbfly/iprobe_v2.git (fetch)
csdn [email protected]:superbfly/iprobe_v2.git (push)
origin ssh://[email protected]:29418/iProbe_v2 (fetch)
origin ssh://[email protected]:29418/iProbe_v2 (push)


这样就可以向多个远程仓库就提交了,

提交的命令为:

向gerrit提交:git push origion master          

向csdn提交:git push csdn master  

你可能感兴趣的:(Git,git)