简体   繁体   中英

How do I merge branches using GitLab CI/CD?

job1:
    stage: build
    script:
        - echo 'Hello'
        - git branch
        - git merge cicd
    tags:
        - cicd

I want to branch merge when I do a job,The following error occurs after executing the job command

merge: cicd - not something we can merge
Did you mean this?
    origin/cicd

I also tried using git checkout master and got the following error

error: pathspec 'master' did not match any file(s) known to git
job1: stage: build script: - echo 'Hello' - git branch - git merge cicd tags: - cicd

I want to merge a branch when I run a job, but the following error occurs after executing the job command:

 merge: cicd - not something we can merge Did you mean this? origin/cicd

Firstly, note that by default, GitLab CI uses shallow clones in order to be faster and to use less resources, which means that it does not fetch all remote references. In which case, it will likely not fetch all the commits necessary to do a proper merge and thus you will have to disable shallow cloning .

Secondly, by default git does not create any branch (other than master /the default branch for normal clones) when cloning a repository. The same error will probably happen if you clone the repository from scratch to your machine with git clone URL , for example. Only references to the remote branches will be fetched by default (such as origin/cicd ).

So you can either merge the remote branch directly:

git merge origin/cicd

Or create a normal branch from the remote branch and then merge:

git branch cicd origin/cicd
git merge cicd

The only difference should be what will be written on the auto-generated merge commit message:


For merging the remote branch directly:

Merge remote-tracking branch 'origin/cicd'

For merging the local branch:

Merge branch 'cicd'


I also tried using git checkout master and got the following error:

 error: pathspec 'master' did not match any file(s) known to git

The same commands above should work for master .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM