Howto change default branch for a repository by CLI or API

Problem to solve

We need to have a bash script that changes the default branch of a repository. I connot find a git CLI command or API operation which could do that

  • I could not find an operation that would do the job. Manually using the UI seems to be the only option.
  • I would expect a API or CLI command to do that job

Steps to reproduce

  • Using gitlab UI create a repository, define a branch (master), define it as the default branch.
  • Using gitlab UI create a second branch (newmaster)
  • use (unix) shell command to change the default branch to “newmaster” (how???)
    -OR-
  • use curl API command to change the default branch to “newmaster” (how???)

Versions

Please select whether options apply, and add the version information.

Versions

The projects API endpoint supports the create action and edit action, which can pass the default_branch parameter.