又到了记录日常测试了。今天测了一下如何给一个项目添加多个仓库(一次提交即可),下面我就把测试过程及代码分享一下。
我们就已gitee和github来测试,首先我们分别创建同名的一个仓库。然后分别把他们的地址粘贴下来
-
gitee
:git@gitee.com:abelethan/spring-cloud-config-repo.git -
github
: git@github.com:AbelEthan/spring-cloud-config-repo.git
我们在桌面右击鼠标选择Git Bash Here
先克隆一个仓库下来,然后查看仓库远程版本库信息:
现在我们把Github仓库地址输入进去
git remote set-url --add origin git@github.com:AbelEthan/spring-cloud-config-repo.git
还有一种方式添加仓库地址就是配置 .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = git@gitee.com:abelethan/srping-cloud-config-repo.git
url = git@github.com/AbelEthan/spring-cloud-config-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
再通过git remote -v
查看远程版本库信息
这里还需要需要设置其他仓库的话,就直接添加(url)就好了
现在我们添加一点文件,然后提交上去。
现在我们看一下而个仓库是不是一样了
- Gitee仓库
- GitHub仓库
这样的方式可以保证多个仓库的代码同步避免了代码的丢失。
还有一种是分步提交的方式,那种是比较简单明了,但是仓库多比较繁琐(如果想一个仓库作为开发版一个仓库作为发布版可以采取这种方式)。