git设置多个远程仓库
1. 添加多个远程仓库,单独push/pull
在添加的原有 origin
远程仓库之后,添加 mirror
远程仓库
git remote add mirror https://url2.com/my_repo.git
对应 .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://url1.com/my_repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "mirror"]
url = https://url2.com/my_repo.git
fetch = +refs/heads/*:refs/remotes/mirror/*
push/pull操作
git pull origin master
git push origin master
git pull mirror master
git push mirror master
2. 原有远程仓库名下添加多个远程仓库
git remote set-url --add origin https://url1.com/my_repo.git
对应 .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://url1.com/my_repo.git
url = https://url2.com/my_repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
3. https 远程仓库免密操作
.git/config配置文件修改
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://${user}:${password}@url1.com/my_repo.git
url = https://${user}:${password}@url2.com/my_repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构