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 @ 2023-01-29 10:44  山岚2013  阅读(522)  评论(0编辑  收藏  举报