实际工作时可能由于git仓库的变动,需要我们将已有代码切换仓库.比如我们先用的gitlab,现在要切换到github上.
迁移命令
代码迁移其实也很简单,先保证本地代码是最新代码
$ git pull -r
修改远程仓库地址
$ git remote set-url origin https://github.com/test/myTest.git
其中https://github.com/test/myTest.git是新的远程仓库的地址.
推送代码到新仓库
$ git push -u origin master
上述的方法能够成功迁移一个分支到新仓库,但是有时候我们的需求是迁移全部代码,即所有分支及tag.一个简单的方法是这样的:
克隆一个完整的项目到本地(包含所有分支及tag)
$ git clone --mirror https://github.com/test/myTest.git
修改远程仓库地址
$ git remote set-url origin https://github.com/test/myTest.git
推送本地所有代码到远程
$ git push --mirror
评论区