某些場合,一個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