Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How can I get the total number of commits across all our team's projects, in the last 12 months?

For an end-of-year report I want to show how many commits our team has made in total this year, across all our BitBucket projects (approx 140 projects).

Is there a way to get a total number of commits for all the projects together?

PS I know this isn't a measure of team effectiveness, but it would be a fun stat to know. Another one would be the total number of lines that have been added or changed, across all projects, or other things like that.

5 answers

1 accepted

3 votes
Answer accepted
Jeff Thomas Atlassian Team Dec 11, 2013

I wanted to do this for my stuff, so I whipped up a quick (and dirty) Python script to get these stats. All of my repositories are under by username, so it was easy to find all the commits. If you let me know how yours are setup, I can probably modify the script. It runs slow, but I'll work on improving it. Let me know if you have any questions, I'll be working on improving it soon.

You'll need to install the requests and python-dateutil modules to run the script.

Sample output

Stats for 2013

Total commits in username/repo1: 21
	Lines added: 1139
	Lines removed: 59

Total commits in username/repo2: 2
	Lines added: 9593
	Lines removed: 0

Total commits in username/repo3: 4
	Lines added: 772
	Lines removed: 75

Total commits: 27
Total lines added: 11504
Total lines removed: 134


import requests, dateutil.parser

baseUrlv2 = ""
baseUrlv1 = ""

username = ""
password = ""
year = 2013

totalCommits = 0
totalAdd = 0
totalRemove = 0
overallAdd = 0
overallRemove = 0
commitCount = 0
commits = []

print ""
print "Stats for {year}".format(year=year)
print ""

r = requests.get("{base}/user/repositories/".format(base=baseUrlv1),
	auth=(username, password))

repos = r.json()

for repo in repos:
	repoSlug = repo['slug']
	r = requests.get("{base}/repositories/{username}/{repo}/commits".format(base=baseUrlv2, username=username, repo=repoSlug),
	auth=(username, password))

	c = r.json()

	while 'next' in c:
		r = requests.get("{next}".format(next=c['next']), 
			auth=(username, password))
		c = r.json()

	for commit in commits:
		commitDate = dateutil.parser.parse(commit['date'])
		if commitDate.year == year:
			commitCount += 1

			r = requests.get("{base}/repositories/{username}/{repo}/changesets/{hash}/diffstat/".format(base=baseUrlv1, username=username, repo=repoSlug, hash=commit['hash']),
				auth=(username, password))
				stats = r.json()
			except ValueError:
			    # decoding failed

			for stat in stats:
					totalAdd += stat['diffstat']['added']
					totalRemove += stat['diffstat']['removed']
				except TypeError:

	print "Total commits in {user}/{repo}: {count}".format(user=username, repo=repoSlug, count=commitCount)		
	print "\tLines added: {add}".format(add=totalAdd)
	print "\tLines removed: {remove}\n".format(remove=totalRemove)
	totalCommits += commitCount	
	overallAdd += totalAdd
	overallRemove += totalRemove
	#reset counters
	commitCount = 0
	totalAdd = 0
	totalRemove = 0
	commits = []

print ""
print "Total commits: {count}".format(count=totalCommits)
print "Total lines added: {count}".format(count=overallAdd)
print "Total lines removed: {count}".format(count=overallRemove)

Wow thanks Jeff, this looks perfect! I'll try it out and report back. But I'm marking this as accepted because it looks like it will do what I need.

Hi Jeff, Thanks for this. I had to add a check after line 32 because repos with no commits were causing an error. if len(c) > 1: Hope that helps someone!

How would this work for a team account?

@joe_midi Hi I believe i ran into that problem today, because all of the repos had different owners it would return a 404 on the second request for every repo, to solve it i changed the following in lines 28 and 29:

repoSlug = repo['slug']
r = requests.get("{base}/repositories/{username}/{repo}/commits".format(base=baseUrlv2, username=username, repo=repoSlug),
auth=(username, password))

For this one:

repoOwner = repo['owner']
repoSlug = repo['slug']
url = "{base}/repositories/{owner}/{repo}/commits".format(base=baseUrlv2, username=repoOwner, repo=repoSlug)
r = requests.get(url, auth=(username, password))

The difference is in the parameter username witch is no longer equal to the account owner you specify on top but to the owner of the repo it is currently looping, i hope it helps.

Just out of curiosity, is this API works for bitbucket server or bitbucket cloud


I am using bitbucket server and that too API version 1.0. I cannot find this API listed .Bitbucket version : Atlassian Bitbucket v5.2.0

Like Ansar Rezaei likes this

Same here. Did you use this with bitbucket server?

I just extended @Jeff Thomas  script for API v2.0 that works on 2021.

You can use it from:

Does this actually work for you?

I get a 401 status code when I try run this. Seems it has to do with the Basic Authentication :\ 

I just extended your script, so that it worked for me (per workspace):

Hi Jeff,

I am looking to generate a report in JIRA for the commits made in the last 12 months which contains fileName, commit Id, JIRA ID, repository Name, Lines changed. Please let me know if you have updated script




0 votes
Deleted user Jul 07, 2020

This is more of a Quesiton for Jeff. Both base URL V1 and V2 seem unsupported now. Is there an update to your script?

If you install extras on your enviroment machine, you can check the history of all your commits and logs.

git summary

Hi Rey

I notice that 'git summary' still only gives me stats for a single repo when used on the local machine. Is there a way to get it to show a total for all commits across every project in a folder, for example?

Hi Ray, when you say 'environment machine', what do you mean, exactly? The source is hosted BitBucket and we have multiple devs who each work from their individual computers.

It does look like a useful tool though, I'll check it out.


I was also looking thsi kind of script for get commit report monthly wise.

I need no of commit report by monthly wise . could You pls suggets,..where and what are need to modify in script

Thank You

The python script does not work for Bitbucket server/ datacenter edition

Hi Gaurav,


For Bitbucket Server/Data Center you may use Awesome Graphs for Bitbucket app.

I.e., the Activity graph shows total number of commits per project or repository during the selected period of time up to 12 months.

Thanks for this Anastasia. Do we have any opensource version of it?

Like Anastasia Voronova likes this

Gaurav, we don't have an opensource version, but you can try it for free and even after the end of the trial period some of the basic features remain available for you. 

Hi Anastasia, Thanks. That's wonderful to know. Can I know what all basic features will remain available in Bitbucket post trial ends?

Hi Gaurav!

Sure! The Contributors, Commits and Punchcard graphs will remain. 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events