You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git新手求助:如何创建独立的第二份代码仓库

最佳操作方案

优先推荐从公司Gitlab克隆原仓库,再推送到新创建的Gitlab独立仓库空间——这种方式最稳妥,完全不会干扰你当前本地和原仓库的配置,步骤也清晰:

操作步骤

  1. 在Gitlab新建空仓库
    登录公司Gitlab,创建一个全新的空仓库(别勾选初始化README、.gitignore这些选项),记好新仓库的Git地址(比如git@company.gitlab.com:your-team/new-migration-repo.git)。

  2. 克隆原仓库到本地临时目录
    打开终端,拉取原Gitlab仓库的完整代码和历史:

git clone git@company.gitlab.com:your-team/original-repo.git temp-clone
cd temp-clone

这一步能确保你拿到的是最完整的主副本,避免本地可能遗留的未提交变更影响副本一致性。

  1. 切换远程地址并推送副本
    移除原仓库的远程关联,换成新仓库的地址,然后推送所有分支(你这里只有master):
git remote remove origin
git remote add origin git@company.gitlab.com:your-team/new-migration-repo.git
git push -u origin master

推送完成后,新仓库就是原仓库的独立完整副本,包含所有提交历史。

备选方案:基于本地仓库创建副本

如果你想基于现有本地仓库生成副本(比如本地有还没推到Gitlab的变更,且想一并包含),也可以这么做,同样不会影响原仓库:

  • 先确保本地所有变更都已提交并推送到原Gitlab仓库(避免副本缺内容):
    git add .
    git commit -m "暂存所有本地变更"
    git push origin master
    
  • 克隆本地仓库到新目录:
    git clone /path/to/your/local/original-repo new-local-copy
    cd new-local-copy
    
  • 替换远程地址为新Gitlab仓库,推送:
    git remote remove origin
    git remote add origin git@company.gitlab.com:your-team/new-migration-repo.git
    git push -u origin master
    

核心注意点

  • 两种方式都不会修改原仓库的任何配置,完全独立,不用担心搞坏现有环境。
  • 优先选从Gitlab克隆的方式,因为Gitlab上的仓库是你对外的权威主副本,能保证副本的完整性和时效性。
  • 新仓库创建后,和原仓库彻底分离,两边的后续变更不会自动同步,完全独立维护。

内容的提问来源于stack exchange,提问作者Oliver Woodall

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 21:50:36