Gitlab runner 13.1.1 checks out a commit and not my branch

I have a .gitlab-ci.yml file that has previously run without issues with Gitlab runner 12.9.0.
The runner has been updated to 13.1.1 and now it no longer checks out to my branch 20-branchname, but instead a commit. (probably the most recent one) This means that the runner cannot merge the branch with the master branch to perform a coherence check because it results in fatal: refusing to merge unrelated histories

*When I have the runner execute git status it prints that HEAD is detached.
*I found this difference in the log raw of two pipelines using different versions of the runner:

e[32;1mChecking out 16b0a39c as 20-branchname...e[0;m
From {repository url}
 * [new ref]         refs/pipelines/127602838 -> refs/pipelines/127602838
 * [new branch]      20-branchname             -> origin/20-branchname
git-lfs/2.8.0 (GitHub; windows amd64; go 1.12.2; git 30af66bb)


e[32;1mChecking out 7410f5aa as 20-branchname...e[0;m
git-lfs/2.8.0 (GitHub; windows amd64; go 1.12.2; git 30af66bb)

*I am using the following versions

  • GitLab: 13.2.0-pre
  • Runner: 13.1.1

*This is how my .gitlab-ci.yml looks:

  - shared-windows
  - windows
  - windows-1809

  - test

# A few templates that help determine when to run a program
  rules: &manual_trigger_on_wip_merge_request
    - if: '$CI_MERGE_REQUEST_TITLE =~ /WIP/'
      when: manual
      allow_failure: false
    - when: always
      allow_failure: false

  rules: &run_always
    - when: always
      allow_failure: false

# Check that the checked in target matches what is being generated.
Coherence Check:
  - .shared_windows_runners
  stage: test
  rules: *manual_trigger_on_wip_merge_request
      # Git setup
    - git config --global ""
    - git config --global "Runner name"
    - git config --global core.safecrlf false
    - git submodule sync
    - git submodule update --init
    - git status
    # Results in detached HEAD
    - git fetch origin
    - git merge origin/master -X ours -m "coherence check merge"
    # It fails here with "fatal: refusing to merge unrelated histories"

*I have also tried to add a git checkout 20-branchname in the .gitlab-ci.yml and while it does lead to git status displaying that my branch has been checked out and not the commit, it still results in the unrelated histories error when It tries to merge with master.

Does anyone have an idea of what difference between Gitlab runner 12.9.0 and 13.1.1 could be the cause?

The issue turned out to be the git depth, which was set to 50 by default. Since the issue emerged around my 50th commit, I set the git depth to “full” in my .gitlab-ci.yml and now it works.