Is it possible to create a new repository in Bitbucket by using command line Git? I have tried the following:
git clone --bare https://username@bitbucket.org
The top answer with cURL wasn't working well for me, so I ended up doing it in Python with Bitbucket-API. Here's the documentation on the repository.create() call.
Install:
pip install bitbucket-api
Python:
>>> from bitbucket.bitbucket import Bitbucket
>>> bb = Bitbucket(username, password)
>>> bb.repository.create('awesome-repo', scm='git', private=True)
(True, {u'scm': ...})
I made a quick shell script that takes care of creating a local git in current working directory, doing the "Initial commit" and then create the bitbucket repo (using Mareks curl method), and then finally doing all that is needed to push the initial commit to bitbucket.
(note this is for private repos only but that is easily changed as described by Patrick)
Use it like this:
fillbucket <user> <password> <reponame>
Code is on http://bitbucket.org/hannesr/fillbucket
@hannester I forked and slightly modified your script.
You had the incorrect remote url (you left your username in the script). Modified it to included Username and Password in the script file.
And renamed, with instructions on how to add to path:
https://bitbucket.org/oscarmorrison/newgit
https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html
$ curl -X POST -v -u username:password -H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/teamsinspace/new-repository4 \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
I've made a slight modification to @pztrick above script. This new script should work the same, but it uses the newer 2.0 API:
function startbitbucket {
echo 'Username?'
read username
echo 'Password?'
read -s password # -s flag hides password text
echo 'Repo name?'
read reponame
curl -X POST -v -u $username:$password -H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/$username/$reponame \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
git remote add origin git@bitbucket.org:$username/$reponame.git
git push -u origin --all
git push -u origin --tags
}
You can place this in your .bashrc or .bash_aliases file (just like the original script).
Note that it will also create this as a private repo. You can change "is_private": "true" to "is_private": "false" to make it a public repo.
You can use the Bitbucket REST API and cURL. For example:
curl --user login:pass https://api.bitbucket.org/1.0/repositories/ \
--data name=REPO_NAME
to create new repository named REPO_NAME
.
See Use the Bitbucket REST APIs for more information.
UPDATE
For Bitbucket V2 specifically, see POST a new repo