克隆仓库代码到新项目,保留git记录

5 阅读1分钟

假设要克隆 aSystem.gitbSystem

bSystem 是定好的目标系统的名字

1. 克隆A系统代码

git clone git@xxx.com:aSystem.git bSystem

🚨注意:我们克隆下来的文件夹名字就改成了 bSystem 省得后面再改名。

cd bSystem

2. 移除原来的远程仓库关联(指的是 aSystem.git)

git remote remove origin

3. 添加新的B仓库地址

git remote add origin git@xxx.com:bSystem.git

4. 推送代码到版权仓库

git push -u origin master

如果版权仓库是空的,这一步就会直接成功。如果仓库不为空(已有提交记录),你可能需要先 git pull --rebase 或强推(慎用): git push -u origin master --force

如果你要复制的不只是 master 分支

git push origin --all