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

Next challenges

Recent achievements


  • Give kudos
  • My kudos


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

3 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?

@Joey Padasian 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?

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. 

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,909 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you