最新消息:

git迁移远程仓库同时保留所有提交记录和所有分支

git ksharpdabu 3984浏览 0评论

 

问题

假设我有A、B两个github账号,如果我想将A的某个仓库转移到B,同时保留提交记录和所有分支,如果不使用官方的git clone,那么如何实现呢?

解决办法:

这里假设你的remote都是origin,同时已经在B上新建了一个同名的空的仓库:
git clone –mirror  <url_of_old_repo>
cd <name_of_old_repo>
此时目录结构如下:
git remote rm origin
git remote add origin <url_of_new_repo>
git push origin –mirror
总结:
网上有使用git checkout,先在本地把所有远程分支拉下来,然后再git push –all origin。但是要是分支很多,一个个拉分支,除非写成脚本,否则手动操作太麻烦了。
参考:
https://gist.github.com/niksumeiko/8972566#gistcomment-1696452
https://gist.github.com/niksumeiko/8972566
https://www.atlassian.com/git/tutorials/git-move-repository
https://datanextsolutions.com/blog/how-to-migrate-git-repository-with-branches-and-commit-history/

 

 

 

转载请注明:大步's Blog » git迁移远程仓库同时保留所有提交记录和所有分支

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址