使用git同时提交到两个远程库


使用git同时提交到多个远程库

法1

1、添加第一个仓库:

git remote add origin https://gitlab.com/XXX/xxx.git

2、添加第二个仓库:

git remote set-url --add origin https://github.com/XXX/xxx.git
  • 如果还有其他仓库,就以此方式继续添加
    3、提交
    git push origin --all
    // or
    git push
    ==================================================================
    // tips:
    // 打开.git/config,可以看到这样的配置:
    
    
    `[remote "origin"]
      url = https://gitlab.com/XXX/xxx.git
      fetch = +refs/heads/*:refs/remotes/origin/*
      url = https://github.com/XXX/xxx.git`
    
    
    // 刚才的命令其实就是添加了这些配置,也可以不用命令行,可以直接编辑该文件,添加对应的url即可

    法2

  • 直接添加另一个远程仓库地址
    git remote add [name] [远程库地址]
    git push [name]
    // [name] 取个远程库名并连接远程地址  然后push上去      git默认的[name]为origin
    
    
    // 如:
    // git remote add test https://github.com/XXX/xxx.git
    // git push test
    
    // 但是想同步两个远程仓库必须同时push && pull
    
    // git push origin
    // git push test
    
    // git pull origin
    // git pull test
    
    
    
    // 查看.gigt中的config文件
    `[remote "origin"]
        url = https://gitlab.com/XXX/xxx.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [remote "test"]
        url = https://github.com/XXX/xxx.git
      fetch = +refs/heads/*:refs/remotes/test/*`

文章作者: Damao
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Damao !
  目录