-->

Tuesday, December 12, 2023

[Solved] Something went wrong when we tried to create 'main' for you: Cannot create branch. The branch name must match this regular expression: (bug|hotfix|feature|release)\/[a-zA-Z0-9]+-[0-9]+-[a-zA-Z0-9-]+/*

 Error:-

While working on a new gitlab repository, when i tried to commit some files into the empty repository it failed with the following error thrown by the pre-receive hook

Something went wrong when we tried to create 'main' for you: Cannot create branch. The branch name must match this regular expression: (bug|hotfix|feature|release|main)\/[a-zA-Z0-9]+-[0-9]+-[a-zA-Z0-9-]+/*

Cause:-

By default Gitlab would restrict the branch name to follow certain standards to make it easier to determine why the branch was created in first place by putting regex like

(bug|hotfix|feature|release)\/[a-zA-Z0-9]+-[0-9]+-[a-zA-Z0-9-]+/* 

so when i tried to create the main branch than also it was expecting the above regex to be matched however that was not the case so it throw the above error. 

Solution :-

It's a good practice to follow naming convention so go ahead and temporarily disable the naming convention in Branch as

repository-->Settings--->Repository--->Push rules--->Branch name

Remove the following values from the Branch name

(bug|hotfix|feature|release)\/[a-zA-Z0-9]+-[0-9]+-[a-zA-Z0-9-]+/*

After that save push rules

Once you have created the main branch than go back and again put the value to follow the regex patter while creating branch in your repository

(bug|hotfix|feature|release)\/[a-zA-Z0-9]+-[0-9]+-[a-zA-Z0-9-]+/*

0 comments:

Post a Comment