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

Bitbucket同步至Github时无法同步所有分支的问题排查

解决Bitbucket Pipeline同步所有分支到GitHub的问题

你的问题核心在于Bitbucket Pipelines默认只会拉取触发流水线的当前分支,哪怕设置了clone: depth: full,也不会自动获取仓库里的所有分支。你本地仓库里没有其他分支的引用,自然没法推送到GitHub。

给你两个修正后的配置方案,任选其一即可:

方案一:用--mirror同步(更简洁)

clone:
  depth: full
pipelines:
  default:
    - step:
        script:
          # 拉取Bitbucket远程仓库的所有分支到本地
          - git fetch origin '+refs/heads/*:refs/remotes/origin/*'
          # 镜像推送所有分支、标签到GitHub
          - git push --mirror git@github.com:orgname/nameofrepo.git

方案二:添加远程仓库后推送

pipelines:
  default:
    - step:
        clone:
          depth: full
        name: 'Sync all branches and tags to GitHub'
        script:
          # 拉取所有远程分支到本地
          - git fetch origin '+refs/heads/*:refs/remotes/origin/*'
          # 添加GitHub作为同步远程仓库
          - git remote add sync git@github.com:orgname/nameofrepo.git
          # 推送所有分支
          - git push sync --all --force
          # 推送所有标签
          - git push sync --tags --force

关键说明:

git fetch origin '+refs/heads/*:refs/remotes/origin/*'这一步是核心,它会把Bitbucket仓库里的所有分支都同步到本地的远程追踪分支(比如origin/feature-dev),这样Git就能识别到所有分支,执行推送命令时才会把所有分支都同步到GitHub。

另外你提到的“分支名称以origin开头”是误解,origin/xxx是本地的远程追踪分支别名,推送时Git会自动映射成GitHub上的同名分支(比如xxx),不会有名称问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 02:57:30