Git同时推送到多个远端仓库【转】

Git同时推送到多个远端仓库【转】

假设你已经将项目上传到github
首先在项目控制台执行

git remote -v

查看到当前项目的远程仓库地址如下:

origin  https://enilu:mypassword@github.com/enilu/material-admin.git (fetch)
origin  https://enilu:mypassword@github.com/enilu/material-admin.git (push)

这里说明下,由于我自己有多个github账号,又懒得配置ssh key,所以直接更改了.git/config文件用:用户名:密码@github.com的方式来管理多个账号的问题。

那么接下来就需要将该项目同时添加到gitee仓库

git remote add gitee https://gitee.com/enilu/material-admin.git

推送到远程仓库:

git push -u gitee

这样就将项目也推送到gitee仓库

后续代码有更新的时候,先提交艾玛,然后使用下面两个命令分别提交到github和gitee

git push -u origin
git push -u gitee

如你所见,上面的方式我们需要推送两次,那么能不能推送一次就可以同时推送到githu和gitee呢,答案是当然可以。

首先删除刚才添加的gitee远程仓库地址

git remote rm gitee

然后用下面命令添加:

git remote set-url --add origin https://gitee.com/enilu/material-admin.git

最后再查看远程仓库地址信息

git remote -v

origin  https://enilu:mygithubpassword@github.com/enilu/material-admin.git (fetch)
origin  https://enilu:mygithubpassword@github.com/enilu/material-admin.git (push)
origin  https://enilu:mygiteepassowrd@gitee.com/enilu/material-admin.git (push)

当然如果记不住命令,也可以直接更改.git/config配置文件,将文件内容更改为如下所示:

[remote "origin"]
    url = https://enilu:mygithubpassword@github.com/enilu/material-admin.git
    fetch = +refs/heads/*:refs/remotes/github/*
    url = https://enilu:mygiteepassowrd@gitee.com/enilu/material-admin.git

怎么样,是不是很简单。
最近金毛瞎搞,搞不好哪天你得github账号就被删除了呢,多存一份放到gitee上也多一分安全。

原作者:enilu 链接:https://www.jianshu.com/p/6c3c4ad98918

原文地址:https://www.cnblogs.com/zhangruifeng/p/15309236.html