首页 > 解决方案 > 无法从 bitbucket 管道 yml 脚本中签出 git 分支

问题描述

在部署到我的 QA 服务器之前,我希望在 staging 之上进行 rebase(或与 staging 合并),这样它将包含来自我的分支的最新更改 + 更改。

作为第一步,我尝试签出暂存并失败:我在 bitbucket-pipelines.yml 中有以下配置

merge:
- step:
    name: merge with staging
    image: node:8
    script:
    - git remote update
    - git fetch origin
    - git branch -f staging origin/staging
    - git checkout staging

错误:

+ git branch -f staging origin/staging
fatal: Not a valid object name: 'origin/staging'.

我确实尝试了许多在本地工作的其他变体,但一切都失败了……看起来 bitbucket 限制了对其他分支的访问……

检查 bitbucket 管道中的分支的正确方法是什么?

标签: gitbitbucketbitbucket-pipelines

解决方案


在 fetch 命令之前,您需要使用以下命令对其进行配置:

- git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

推荐阅读