Git本地仓库关联多个远程仓库
前言
有一个公司的项目,可能是通过公司的内网搭建的GitLab,但是自己又想偷偷保存到自己私密仓库上,以备不时之需,这时我们只需要这样做就行。
例如我们两个仓库:
sh
https://gitee.com/qqlcx5/frontend.git // 仓库一
https://github.com/qqlcx5/frontend.git // 仓库二set-url命令
关联第一个仓库:
sh
git remote add origin https://gitee.com/qqlcx5/frontend.git关联多个远程仓库:
sh
git remote set-url --add origin https://github.com/qqlcx5/frontend.git推送到多个远程仓库:
sh
git push origin --all修改.git文件
在项目中,git初始化后都有一个.git文件夹的隐藏文件,通过编辑器打开.git/config文件后
可以看到这样的配置:
sh
[remote "origin"]
url = https://gitee.com/qqlcx5/frontend.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/qqlcx5/frontend.git // 新增远程仓库大功告成。