Qvatra
Qvatra

Reputation: 3857

Can not checkout a git branch from a bitbucket pipeline yml script

I want to have rebase on top of staging (or merge with staging) before I deploy to my QA server so it will contain the latest changes + changes from my branch.

As a first step I tried to checkout staging and failed: I have the following configuration in 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

error:

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

I did try a lot of other variants that are work locally but everything fails... looks like bitbucket limits access to other branches..

What is the correct way of checking out branches in bitbucket pipelines?

Upvotes: 6

Views: 2288

Answers (2)

videomugre
videomugre

Reputation: 328

Before the fetch command, you need to configure it with this:

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

Upvotes: 4

Qvatra
Qvatra

Reputation: 3857

the following seems to be the solution for my issue as I can avoid checking out staging:

name: Build and test on QA env
image: node:8
script:
  - git fetch origin
  - git pull --rebase origin staging --verbose
  - npm ci
  - npm test
  - npm run build

from the other hand it doesn't answer asked question so I leave this 'open' for now

Upvotes: -1

Related Questions