What to Do if GitVersion Does Not Recognise Your Main Branch

At the user group site, we use GitVersion to turn our git history into a Semantic Version number. After we switched to main as the default branch, our build failed with this error message:

ERROR [****] An unexpected error occurred: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.

GitVersion did not recognise the main branch and we needed to make a little change to the GitVersion.yml file to fix this problem:

assembly-versioning-scheme: MajorMinorPatchTag
mode: ContinuousDeployment
next-version: 0.3.1
branches:
  master:
    regex: main
    mode: ContinuousDeployment
  feature: {}
ignore:
  sha: []

This change should normally not be necessary. For reasons unknown to us, the newest version of GitVersion needed this extra nudge to accept the main branch. Try it if you run into the same problem.