背景:
近期,我们需要将一个老的git仓库迁移到新的仓库,并且要将所有的commit history、branches、tags都迁过去。
查了很多资料,用了三种方式,在最后一种成功了,并且步骤超级简单。
实现方式:
1.从老仓库克隆一份裸版本库。
git clone --bare git://oldgithub.com/username/oldproject.git
2.在新的Git服务器上创建一个新仓库,比如叫newproject。
3.以镜像推送的方式上传代码到newproject服务器上。
cd oldproject.git
git push --mirror git@newgithub.com/username/newproject.git
4.删除本地代码
cd ..
rm -rf oldproject.git
5.切换远程仓库地址。在本地的代码仓库执行如下,即可完美过渡。
git remote set-url origin git@newgithub.com/username/newproject.git
收工。本地代码仓库可以像往常一样commit、push。