概述
需求如下:我在git.oschina.net提交了项目,现在想转到github。最终想达到的效果是:每次提交代码,github跟git.oschina.net同时更新。
我的代码仓库地址如下:
github
git.oschina.net
背景介绍
目前我的git config文件内容如下:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = https://git.oschina.net/0604hx/nerve-tools.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
按照自己搜索出来的方法,执行以下命令时出错了(fatal: remote origin already exists.):
git remote add origin https://github.com/0604hx/nerve-tools.git
解决
后来发现,只需要在原来的config中加入新的地址即可,修改后的配置如下
此时执行代码提交:
git push -u origin master
会让你输入两个仓库的登录帐密,然后就ok了。