首页 > 有没有办法同步 Coding 与 GitHub

有没有办法同步 Coding 与 GitHub

如果一个项目同时在 GitHub 和 Coding 上都有仓库,能不能一次 commit 就可以更新到两个地方?


你可以使用 git remote set-url 命令来实现,以 Coding 和 GitHub 为例:

$git remote -v #查看当前远端仓库
origin  git@git.coding.net:user/project.git (fetch)
origin  git@git.coding.net:user/project.git (push)
github  git@github.com:user/repo.git (fetch)
github  git@github.com:user/repo.git (push)


$git remote add both git@git.coding.net:user/project.git
# 添加一个名为 both 的远端
$git remote set-url --add --push both git@git.coding.net:user/project.git
# 为其添加 push 到 Coding 的 SSH 地址
$git remote set-url --add --push both git@github.com:user/repo.git
# 为其添加 push 到 GitHub 的 SSH 地址

(注意如果你选择使用 SSH 方式推送,预先要 配置 SSH 公钥)
之后即可通过使用 git push both 同时推送到两个远端仓库。


git同时push到多个仓库

为防止一个git仓库由于各种原因造成无法访问,可以将代码push到多个仓库。

编辑本地仓库目录下面的.git目录下的config文件。

添加:

[remote "all"]
url = git@github.com:licess/licess.git
url = git@gitcafe.com:licess/licess.git

再push时,运行

git push all master

github 支持 hook,你可以设置一下。自己拿台服务器出来做这个。这样你每次push到github后就会触发 hook,实现与 gitcafe 的自动同步。

【热门文章】
【热门文章】