Got an interesting error on Gitlab today. On an MR that had passed tests and had been approved, Gitlab would not allow the branch to be merged because “The source branch [Branch Name] does not exist. Please restore it or use a different source branch.”
Checking the “Changes” tab in Gitlab showed all of the changes that I expected to see. So Gitlab could see the changes and knew the branch name.
I checked the commit SHA connected to the branch, and Gitlab showed all of the changes that I expected to see. Gitlab knew the correct SHA and was associating the SHA with the branch name, but the “Overview” tab still showed the error message “The source branch [Branch Name] does not exist. Please restore it or use a different source branch.”
I Googled to see if anyone else had had the issue. Many people had. This issue report on Gitlab.com shows that the problem goes back at least 3 years. The official response from Gitlab is that “This is no longer an active issue.”
I beg to differ. I’m using GitLab Enterprise Edition 14.8.6-ee and it still has this issue.
I cloned a fresh copy of the repo from Gitlab on my laptop and checked the branches with:
git branch -a
The branch was listed. I checked it out. It checked out just fine. I diffed it against the main branch. All of the changes were present.
So the branch exists on the repository on the server, it has all of the changes in it that I expect, there is nothing wrong with the Git repo itself, it’s just Gitlab that has some sort of disconnect.
To work around the problem I added an empty commit to the branch and pushed it to the Gitlab repo:
$ git commit --allow-empty -m "Empty commit" $ git push
Once I did that the error message cleared. Gitlab had to re-run the tests, but once the tests passed I could merge the branch.
Hope you find this useful.Follow earlruby