当前位置:   article > 正文

git 一套代码关联多个远程仓库(可同步更新到多个,也可一个一个更新)_git关联两个仓库

git关联两个仓库


背景

本文主要讲述在平时开发中,一份代码可能有多份远程仓库的情况下,需要更新到不同的仓库 以及 同步更新到所有的仓库


一、一套代码关联多个远程仓库,按需更新

1.本地创建好项目文件夹

2.打开终端, cd进入 项目文件夹 , 然后初始化

git init
  • 1

3.添加仓库地址

git remote add  仓库名1  仓库地址
git remote add  仓库名2  仓库地址
git remote add  仓库名3  仓库地址
  • 1
  • 2
  • 3

4.查看关联的仓库地址情况

git remote -v 
  • 1

5.add文件

git add .
  • 1

6.commit

git commit -m"提交版本描述"
  • 1

7.提交到仓库

git push 仓库名1 master
git push 仓库名2 master
git push 仓库名3 master
  • 1
  • 2
  • 3

8.拉取代码

git pull 仓库名1 master
git pull 仓库名2 master
git pull 仓库名3 master
  • 1
  • 2
  • 3

二、一套代码一次性提交到所有的仓库

1.删除其余的仓库

提示:这里举的例子在上面的基础上修改,也可在关联远程仓库时,跳到第二步

git remote rm  仓库名1
git remote rm  仓库名2
  • 1
  • 2

2.添加远程仓库

提示:这里关联的仓库名称都是一样的

git remote set-url --add 仓库名3  仓库地址1
git remote set-url --add 仓库名3  仓库地址2
  • 1
  • 2

3.查看关联的仓库地址情况

git remote -v .
  • 1

4.一次性提交

git add .
git commit -m"提交版本描述"
git push 仓库名3 master
  • 1
  • 2
  • 3

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/989404
推荐阅读
相关标签
  

闽ICP备14008679号