方法一:(使用 “git remote add 仓库名” 命令)--推荐
第一个仓库(默认仓库)
git remote add origin https://github.com......
git push -u origin master
第二个仓库(newRepository 便是第二仓库)
git remote add newRepository https://github.com......
git push -u newRepository master
取消关联时:git remote remove newRepository
在控制台中 输入 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两次(每一个仓库都需要单独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地址,可以灵活操作两个仓库,所以个人推荐方法一。
来源:oschina
链接:https://my.oschina.net/u/200350/blog/4329625