Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Gitlab CI/CD how to checkout another branch during the pipeline

I would like to checkout to dev branch in a merge request pipeline that is opened for merging to dev with some other branch. I am going to check somethings in this job and then continue with some other jobs depending on the success of this one. Is it possible to do such thing or do I always have to work with the branch the pipeline triggered at?

I add the related part of the gitlab configuration


variables:
  GIT_STRATEGY: clone

checksomething:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH
  environment:
    name: development
  before_script:
    - git checkout dev
  script:
    - !reference [.check-something-on-dev]

But I have this error:

$ git checkout dev
error: pathspec 'dev' did not match any file(s) known to git```
like image 483
iRestMyCaseYourHonor Avatar asked Oct 12 '25 11:10

iRestMyCaseYourHonor


1 Answers

Actually it was this easy:

    before_script:
    - git fetch origin dev
    - git checkout dev
like image 135
iRestMyCaseYourHonor Avatar answered Oct 15 '25 20:10

iRestMyCaseYourHonor