Gitlab strategy, runners and mirroring

hello everyone,

I have a problem which simply baffles me and I really hope that someone can help me understand what’s going on.

What I am trying to achieve?

I have repo A which sits on my server and of course it’s managed with gitlab.
I have repo B which sits somewhere else but obviously I have access there also.

I’m using gitlab ci.
The end goal is to be able from within the pipeline execution to mirror repo A in repo B. Basically, each time a commit is done on a certain branch in repo A (e.g. develop) to push(mirror) the state of the branch in repo B.

What I’ve done so far?

  1. I changed the git strategy from fetch to clone

  2. Created a simplified .gitlab-ci.yml

(excerpt)
mirror_develop:
stage: mirror
only:
- develop
script:
- git branch
- git remote add --mirror=push --tags mirror git@gitlab…
- git push mirror

What makes me wonder is that when this runs, the git branch command returns:

  • (HEAD detached at bd9cd5a)
    master

And what follows is basically deleting an existing develop branch on repo B when pushing.
But the actual content of the files are indeed the ones from the develop branch in repo A which get into the master branch in repo B. Which of course is not the desired outcome.

(I see all of this in the gitlab’s console view of the pipeline)

My expectation, which can be misguided of course, was that since the pipeline runs only for then develop branch when the repo is cloned by the runner, during the pipeline execution, then what one will get when running git branch will be the actual develop branch but that’s not the case.

I would appreciate it immensely if someone could explain why is this working in that way.
Is this git related or gitlab/gitlab-runner related?

Thank you,
Roger

By the way:

mirror_develop:
stage: mirror
only:
- develop
script:
- git branch
- git checkout develop
- git remote add --mirror=push --tags mirror git@gitlab…
- git push mirror

This does what I need but seems kind of dumb.

If anyone is interested I found the answer.
The reason why git branch returned master in my case was because master was the default branch.
It will always return the default branch set in gitlab! :slight_smile:

Roger