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 添加一个远程仓库,其中name可以任意指定

 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 给已有的名为name 的远程仓库添加一个远程地址

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 更加便捷简单
posted @ 2023-07-28 19:45  贝壳里的星海  阅读(24)  评论(0编辑  收藏  举报