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

如何将现有分支推送至新GitLab仓库?跨仓库分支迁移重命名方法

操作方案

一、从仓库A克隆指定分支并以新名称推送至仓库B

最优方式是用浅克隆仅拉取目标分支(避免下载仓库全量历史,提升效率),再推送至仓库B并指定新分支名:

  1. 克隆仓库A的目标分支(假设原分支名为old-branch):
git clone --branch old-branch --single-branch https://gitlab.com/your-username/repo-A.git
cd repo-A
  1. 添加仓库B作为新远程(命名为repo-B便于区分):
git remote add repo-B https://gitlab.com/your-username/repo-B.git
  1. 将当前分支以新名称(比如new-branch)推送至仓库B:
git push repo-B old-branch:new-branch

若后续无需关联仓库A,可删除原远程:

git remote remove origin

二、将本地现有分支推送至新GitLab仓库

假设本地已有分支local-branch,要推送至新仓库C:

  1. 添加新仓库C作为远程:
git remote add repo-C https://gitlab.com/your-username/repo-C.git
  1. 推送分支至新仓库(若要设置上游关联,方便后续拉取/推送,加上-u参数):
# 仅推送分支
git push repo-C local-branch
# 推送并设置上游关联
git push -u repo-C local-branch

如果需要给远程分支改名,格式如下:

git push repo-C local-branch:new-remote-branch

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 16:44:55