Make a request on https://api.github.com/repos/{username}/{repo}/commits?sha={branch}&per_page=1&page=1
Now just take the Link
parameter of the response header and grab out the page count situated just before rel="last"
This page count is equal to the total number of commits in that branch!
The trick was to use &per_page=1&page=1
. It distributed 1 commit in 1 page. So, the total number of commits will be equal to the total number of pages.