6.git本地链接多个远程仓库
git同时链接多个仓库
查看本地仓库所关联的远程仓库
$ git remote -v
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (fetch)
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (push)
方法1.独立仓库操作
新增本地链接链接仓库
git remote add
git remote add codeup https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/xiaobei/lcodeNoteCards.git
再次查看本地仓库所关联的远程仓库
$ git remote -v
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (fetch)
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (push)
codeup https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/xiaobei/lcodeNoteCards.git (fetch)
codeup https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/xiaobei/lcodeNoteCards.git (push)
指定推送代码
$ git push origin master
$ git push codeup master
指定拉取代码
$ git pull origin master
$ git pull codeup master
方法2.无需额外操作
远程仓库添加额外URL
不额外添加远程仓库,而是给现有的远程仓库添加额外的URL
使用git remote set-url -add
git remote set-url --add origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/xiaobei/lcodeNoteCards.git (push)
$ git remote -v
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (fetch)
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/beike/lcodeNoteCards.git (push)
origin https://codeup.aliyun.com/62b3ddce98b10058fdb7b9ba/xiaobei/lcodeNoteCards.git (fetch)
$ git pull origin
$ git push origin
总结
- 方法1 适合存在内网情况
- 方法2 更加便捷简单