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

引用

posted @   山岚2013  阅读(538)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示