Search code examples
gitlabgitlab-api

How can I get all the branches of a project using Gitlab API?


Trying to get all the branches under a project using GitLab API, but I can see only 20 branches are returned. How can I get the complete list of all the branches? I am using the following API.

curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/1521/repository/branches"

Solution

  • Found the solution under pagination in the official Gitlab API documentation, by default we get 20 results, we can increase the number of results by using per_page in our API link as follows.

    https://gitlab.com/api/v4/projects/<Project_id>/repository/branches?per_page=50