某些场合,一个git项目须要能同时使用两个甚至多个远程仓库,好比国内+国外、测试环境+生产环境,等等。在项目的根目录查看git配置文件,通常来讲是这样的:git
$ cat .git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = https://git.oschina.net/mvpboss1004/Availability.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
可见,咱们经常使用的git remote add origin https://git.oschina.net/mvpboss1004/Availability.git
中,origin只是个名字。github
修改config文件,加入另外一个远程仓库,并为其命名,好比称为mirror:ide
[remote "origin"] url = https://git.oschina.net/mvpboss1004/Availability.git fetch = +refs/heads/*:refs/remotes/origin/* [remote "mirror"] url = https://github.com/mvpboss1004/Availability.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin remote = mirror merge = refs/heads/master
使用如下命令,能够分别从两个远程仓库pull:测试
git pull origin master git pull mirror master
使用如下命令,能够分别push到两个远程仓库:fetch
git push origin master git push mirror master