Create new repo on Bitbucket from Git Bash terminal?
Solution 1:
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
Solution 2:
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" }'
Solution 3:
Here is @hannesr's script tweaked a bit to accept input from prompts:
# startbitbucket - creates remote bitbucket repo and adds it as git remote to cwd
function startbitbucket {
echo 'Username?'
read username
echo 'Password?'
read -s password # -s flag hides password text
echo 'Repo name?'
read reponame
curl --user $username:$password \
https://api.bitbucket.org/1.0/repositories/ \
--data name=$reponame \
--data is_private='true'
git remote add origin [email protected]:$username/$reponame.git
git push -u origin --all
git push -u origin --tags
}
You should place this in your .bashrc
or .bash_aliases
.
Solution 4:
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 [email protected]:$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.
Solution 5:
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