Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab Api Commits Behind/Ahead Master

On the Gitlab webpage you have the possibility to check how many commits a branch is behind or ahead of the master branch. My question is if it is possible to get information about this with the "gitlab API"? I checked the docs but unfortunately couldn't find anything.

like image 644
Tessaiga Avatar asked Aug 16 '26 05:08

Tessaiga


1 Answers

The specific Gitlab API that does the trick is

GET /projects/:id/repository/compare

More info at https://docs.gitlab.com/ee/api/repositories.html#compare-branches-tags-or-commits

Execution example to bring you number of commits that differentiates the 2 branches

curl -s --header "PRIVATE-TOKEN: <access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/compare?from=<branch_name_behind_in_commits>&to=<branch_name_ahead_in_commits>&straight=true" | jq '. | .commits | length'
  1. If you want to see how many commits is master branch behind of feature branch. You should add the master to from field and feature branch at to field
  2. If you want to see how many commits is master branch ahead of feature branch. You should add the feature branch to from field and master branch at to field
like image 63
Tolis Gerodimos Avatar answered Aug 17 '26 19:08

Tolis Gerodimos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!