Count number off commits for a repository using API v2


Does anyone have a reasonably good method of finding the total number in a repository ie total items in all pages of : GET /repositories/{username}/{repo_slug}/commits/ without having to iterate throught each page?

I was hoping that there would be a size attribute similar to the attribute returned in the




Unfortunately, no we do not. This is because this is a very expensive operation for git since you have to walk the DAG from each ref. In fact, your method is also approximate since there might be a push after you start paginating.

I guess that means the only option is to clone then use git natively:

git rev-list --all --count