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
相关产品推荐
相关产品推荐

