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

如何将其他派生仓库分支导入目标派生仓库并安全删除原仓库?

操作步骤:合并派生仓库分支到目标仓库并安全删除原仓库

1. 准备目标仓库本地环境

  • 若未克隆forked_repo_1,先执行:git clone <forked_repo_1的远程地址>
  • 进入仓库目录:cd forked_repo_1

2. 迁移forked_repo_2的branch_2为forked_repo_1的branch_3

  • 添加forked_repo_2作为临时远程:git remote add repo2 <forked_repo_2的远程地址>
  • 拉取该仓库的所有分支数据:git fetch repo2
  • 基于repo2的branch_2创建本地branch_3:git checkout -b branch_3 repo2/branch_2
  • 把本地branch_3推送到forked_repo_1的远程服务器:git push origin branch_3
  • (可选)清理临时远程配置:git remote remove repo2

3. 迁移forked_repo_3的branch_2为forked_repo_1的branch_4

  • 添加forked_repo_3作为临时远程:git remote add repo3 <forked_repo_3的远程地址>
  • 拉取该仓库的所有分支数据:git fetch repo3
  • 基于repo3的branch_2创建本地branch_4:git checkout -b branch_4 repo3/branch_2
  • 把本地branch_4推送到forked_repo_1的远程服务器:git push origin branch_4
  • (可选)清理临时远程配置:git remote remove repo3

4. 验证分支迁移结果

  • 查看本地和远程分支:git branch -a,确认branch_3、branch_4以及对应的远程分支origin/branch_3、origin/branch_4都存在
  • 也可以直接登录Git平台查看forked_repo_1的远程分支列表,确认两个新分支已成功推送

5. 安全删除原派生仓库

  • 确认上述分支都已存储在forked_repo_1的远程服务器后,就可以在Git平台上删除forked_repo_2和forked_repo_3了。此时新分支已经完全属于forked_repo_1,原仓库删除不会对它们造成任何影响

关键提示

  • 分支迁移的核心是将新分支推送到目标仓库的远程服务器,一旦完成推送,分支数据就和原派生仓库解绑,存储在目标仓库的服务器上,不用担心原仓库删除导致数据丢失。
  • git fetch仅用于获取原仓库的分支数据,不会影响本地现有分支,操作安全。

内容的提问来源于stack exchange,提问作者Сеня Корягин

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 14:35:21