因为家里github经常出现无法访问的情况,同时支持国内企业,因此开始最近开始使用gitee,但还希望将项目同步推送github,又不想每次都手动推2次。

  1. 进入 .git 目录下,打开 config 文件,默认文件内容如下
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://gitee.com/geekidentity/showcase.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
  1. 只需在 [remote "origin"] 添加需要推送的其他git地址,例如github 或自己的 gitlab

url = https://github.com/geekidentity/showcase.git

编辑完成如下:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://gitee.com/geekidentity/showcase.git
        url = https://github.com/geekidentity/showcase.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

此时再推送 git push,则会按 url 的顺序依次推送。

当 pull 时,默认为添加的到origin的第一个地址。

参考

  1. https://www.cnblogs.com/haoxianrui/p/13650849.html
  2. https://blog.csdn.net/sinat_34560749/article/details/104051822