semver icon indicating copy to clipboard operation
semver copied to clipboard

Gitlab CI/CD - `src refspec main does not match any`

Open michalvadak opened this issue 1 year ago • 4 comments

When you push in Gitlab CI like git push origin main you will get this error

error: src refspec main does not match any.
error: failed to push some refs to 'https://gitlab-ci-token/:[MASKED][email protected]/gc/packages.git'

Proposed solution Push like this git push origin HEAD:main then it works

More info here

michalvadak avatar Jun 14 '23 00:06 michalvadak

Same happens to me in Azure DevOps. What i noticed is that pipelines (at least in Azure DevOps) by default checkout to detached HEAD and seems to haves no knowledge of other branches. What I did is that I added git fetch && git checkout to main branch before I run version command. I don't know if this is the best solution, but it's an easy one. In another project I am using semantic-release tool which had no problems with pushing changes back to designated branch. Hope this helps :)

gregorsintic avatar Jun 15 '23 12:06 gregorsintic

Yeah, the semantic-release is actually using the git push origin HEAD:main

Link

michalvadak avatar Jun 15 '23 13:06 michalvadak

Thanks @michalvadak for raising the issue. We'll have to dive into this. Meanwhile, could you confirm that using baseBranch: 'HEAD:main' works for you? Thank you 🙏

yjaaidi avatar Jun 15 '23 16:06 yjaaidi

baseBranch: 'HEAD:main' works fine

michalvadak avatar Jun 19 '23 12:06 michalvadak