一个Git项目多个仓库

方法一:(使用 “git remote add 仓库名” 命令)--推荐

  第一个仓库(默认仓库)

  git remote add origin https://github.com......
  git push -u origin master

  第二个仓库(着色部分便是第二仓库)

git remote add newRepository https://github.com......
git push -u newRepository master
取消关联时:git remote remove newRepository
git remote
newRepository
origin

git remote -v
newRepository   https://github.com/lixy-github/newRepository.git (fetch)
newRepository   https://github.com/lixy-github/newRepository.git (push)
origin  http://....com:5678/gitbucket/git/Li.XY/Pride.git (fetch)
origin  http://....com:5678/gitbucket/git/Li.XY/Pride.git (push)

  可以看到两个仓库状态,但是要push两次。

 

方法二:(使用 git remote set-url” 命令)  

git remote set-url --add newRepository https://git.hub.com/......
git remote -v
newRepository   https://github.com/lixy-github/newRepository.git (push)
origin  http://....com:5678/gitbucket/git/Li.XY/Pride.git (fetch)
origin  http://....com:5678/gitbucket/git/Li.XY/Pride.git (push)

  可以看到远程仓库有两个 push 地址,这种方法的好处是每次只需要push一次就可以了。

 

方法三:

  打开 .git/config 找到 [remote "github"],添加对应的 url 即可,效果如下。这种方法其实和方法二是一样的。

[remote "github"]
    url =http://....com:5678/gitbucket/git/Li.XY/Pride.git
    fetch = +refs/heads/*:refs/remotes/github/*
    url = https://github.com/lixy-github/newRepository.git 

 

方法二和方法三在push的时候比较方便,但是只有1个拉取地址,而方法一有2个拉取地址和2个push地址,所以个人推荐方法一。

posted @ 2019-01-21 14:48  新码将  阅读(3836)  评论(0编辑  收藏  举报