Create new repo on Bitbucket from Git Bash termina

2019-01-29 23:41发布

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/username/new_project.git

I get this message:

Cloning into bare repository 'new_project.git'...
fatal: https://username@bitbucket.org/username/new_project.git/info/refs not found: did you run git update-server-info on the server?

It would be nice to do this without going to the web app.

标签: git bitbucket
9条回答
淡お忘
2楼-- · 2019-01-30 00:06

More recently, we can just use bitbucket-cli.

Install it using pip

pip install bitbucket-cli

Then create a repo using

bitbucket create --private --protocol ssh --scm git YOUR_REPO_NAME

Note that this creates a private git repo, you can use --public for public access and --scm hg if you use Mercurial. Username argument can be added via --username YOUR_USER_NAME.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-30 00:07

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

查看更多
三岁会撩人
4楼-- · 2019-01-30 00:08

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.

查看更多
迷人小祖宗
5楼-- · 2019-01-30 00:10

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" }'
查看更多
干净又极端
6楼-- · 2019-01-30 00:17

@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

查看更多
淡お忘
7楼-- · 2019-01-30 00:22

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': ...})
查看更多
登录 后发表回答