Get default branch name of a project via API

Hi there.

How I can get default branch name of a project via API from these page: /-/settings/repository → Branch defaults → Default branch.

Thanks.

1 Like

Hi

You can use Gitlab API and jq to parse the output . for example this return the name of default branch of project with $PROJECT_ID :

curl -sS --header “PRIVATE-TOKEN: $YOUR_ACCESS_TOKEN” “http://gitlab.example.com/api/v4/projects/$PROJECT_ID/repository/branches” | jq -r ‘.[]|select (.default==true)|.name’

2 Likes