Programmatically create Stash GIT repos

Is there a way to programmatically create GIT repos in Stash (running Postgres). I need to create 40 odd blank starters in a central model, I have the list of names I want to use.

2 answers

1 accepted

9 votes
Accepted answer
Seb Ruiz Atlassian Team Jun 28, 2012


You can use the Stash REST apis to do this. If you would like to see all the REST endpoints, please have a read through the REST apis or install the REST api browser plugin in Stash.

The REST endpoint you will want to use is as follows:

curl -u user:pass -X POST -H "Accept: application/json"  -H "Content-Type: application/json" "http://stash/projects/QA/repos/" -d '{"name": "Repository Name"}'

What does it mean if I get an error message stating the following:


Seb Ruiz Atlassian Team Sep 04, 2012

It means that your request is malformed. Unfortunately it seems that Stash is not providing a good error message in this exact circumstance. If you provide the details of the request you are creating (headers, url, content) then I can look into it and fix your request and also make sure we do better error handling for this case.

The initial post by Seb worked for me as is.

Just don't forget to put /repos/ at the end of your stash project name. eg.


Initially, I only had


so it didn't work.

Edit: It now seems to be working with wget but not curl. Clearly this is just a curl issue so I think I will just drop it and use wget. Thanks again for the help.

Thanks, Seb. I actually managed to create a repo by manually creating an http request through a proxy. Here is the request that worked:

POST /rest/api/1.0/projects/[Project Name]/repos HTTP/1.1
Host: [hostname]
Connection: keep-alive
Authorization: Basic [user:pass (Base64)]
Content-Length: 29
Cache-Control: max-age=0
Origin: https://[hostname]
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
Content-Type: application/json
Accept: application/json
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

curl -k -X POST -H "Host: [hostname]" -H "Connection: keep-alive" -H "Authorization: Basic [user:pass(Base64)]" -H  "Content-Length: 29" -H "Cache-Control: max-age=0" -H "Origin: https://[hostname]" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1" -H "Content-Type: application/json" -H "Accept: application/json" -H "Accept-Encoding: gzip,deflate,sdch" -H "Accept-Language: en-US,en;q=0.8" -H "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3" --data {"slug":"test", "name":"test"} https://[hostname]/rest/api/1.0/projects/[projectName]/repos/
wget --no-check-certificate --header='Host: [hostname]' --header 'Connection: keep-alive' --header 'Authorization: Basic [user:pass(Base64)]' --header 'Content-Type: application/json' --header 'Accept: application/json' --post-data='{"slug":"test", "name":"test"}' https://[hostname]/rest/api/1.0/projects/[projectName]/repos/

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

180 views 3 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you