Git 推送到多个远程仓库
作者:Grey
原文地址:Git 推送到多个远程仓库
针对新建项目
在GitCode和GitHub上分别新建两个不包括任何文件的空仓库(若是两个已经有文件的仓库,请参见关联已经存在的项目章节说明)
在本地新建一个algorithm
的文件夹,在该文件夹目录下执行:
git init
然后执行
git remote add origin https://gitcode.net/hotonyhui/algorithm.git
git remote set-url --add origin https://github.com/GreyZeng/algorithm.git
测试提交
在本地仓库algorithm
文件夹中增加一个文件readme.txt
,依次执行
git add readme.txt
git commit -m "add readme.txt"
git push -u origin master
即可将readme.txt
推送到 GitHub 和 GitCode 两个仓库中。
关联已经存在的项目
用以上algorithm仓库进行说明
两个仓库已经有一个readme.txt
文件
在本地新建一个algorithm
的文件夹,在该文件夹目录下执行:
git init
然后执行
git remote add origin https://github.com/GreyZeng/algorithm.git
git remote set-url --add origin https://gitcode.net/hotonyhui/algorithm.git
从默认仓库中fetch下文件
git pull origin master
测试一下
在本地仓库algorithm
文件夹中增加一个文件readme2.txt
,依次执行
git add readme2.txt
git commit -m "add readme2.txt"
git push -u origin master
即可将readme2.txt
推送到 GitHub 和 GitCode 两个仓库中。