Creating master branch via gitlab api


#1

Hi,

POST api/v3/projects sets the default_branch to null. Not sure whether this is intentional. If so, how can I create a master branch via api ?

I need a source branch for creating other branches & MRs via apis


#2

Hi @selvagsz,

you can use the API to create branches. Please take a look into this documentation about branches API.


#3

@felipe While creating a new branch, what would be the ref branch when there is no master branch available ?


#4

I’ve checked again on this, you’re right, is not possible to create branches through the API on an empty project as the repo is not created by default.

The default branch for a project is now nil (blank) upon creation, and it will set the default branch to whatever branch is pushed first.

So you need to push a branch in order to get it to work.


#5

You can create a master branch by creating a files ( it will generate master)
Here is the documentation:
https://docs.gitlab.com/ee/api/repository_files.html#create-new-file-in-repository