从Git Bash终端在Bitbucket上创建新的回购?

Pat*_*ick 70 git bitbucket

是否可以使用命令行Git在Bitbucket中创建新的存储库?我尝试过以下方法:

git clone --bare https://username@bitbucket.org/username/new_project.git
Run Code Online (Sandbox Code Playgroud)

我收到这条消息:

克隆到裸存储库'new_project.git'...
致命:https://username@bitbucket.org/username/new_project.git/info/refs找不到:你在服务器上运行git update-server-info了吗?

如果不去网络应用程序就可以做到这一点.

Mar*_*rek 89

您可以使用Bitbucket REST API和cURL.例如:

curl --user login:pass https://api.bitbucket.org/1.0/repositories/ \
--data name=REPO_NAME
Run Code Online (Sandbox Code Playgroud)

创建名为的新存储库REPO_NAME.

有关更多信息,请参阅使用Bitbucket REST API.

UPDATE

具体来说,对于Bitbucket V2,请参见POST一个新的回购

  • 谢谢,简单易解决.值得注意的是,上面创建了一个公共回购.只需为私人仓库添加--data is_private ='true'即可 (32认同)
  • 从安全的角度来看,我会将`--user login:pass`更改为`--user login`并每次手动输入密码,因此它不会保存在`.bash_history`中(或者,如果你是在OS X上,您可以使用命令行安全地从钥匙串中检索密码,此处有更多信息,例如:http://joshtronic.com/2014/02/17/using-keyring-access-on-the-osx-commandline/). (8认同)
  • 对我来说,我输入了错误的密码,但curl没有告诉我它有401未经授权.添加-v让我看看发生了什么. (4认同)
  • 我需要创建一个不在我账户下的回购,但在我所属的团队中.API显示了这一点,但添加了--data owner = <team name> (3认同)
  • @Stephen 下面的帖子 http://stackoverflow.com/a/19670989/951349 有点更新。 (2认同)

Ste*_*hen 49

最近,我们可以使用bitbucket-cli.

使用安装它 pip

pip install bitbucket-cli
Run Code Online (Sandbox Code Playgroud)

然后使用创建一个repo

bitbucket create --private --protocol ssh --scm git YOUR_REPO_NAME
Run Code Online (Sandbox Code Playgroud)

请注意,这会创建一个私有git仓库,您可以使用它--public进行公共访问,--scm hg如果您使用Mercurial.用户名参数可以通过添加--username YOUR_USER_NAME.

  • 不支持Python 3. (5认同)

pzt*_*ick 11

这是@ hannesr的脚本调整了一点来接受来自提示的输入:

# 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 git@bitbucket.org:$username/$reponame.git
    git push -u origin --all
    git push -u origin --tags
}
Run Code Online (Sandbox Code Playgroud)

你应该把它放在你的.bashrc.bash_aliases.

  • 我喜欢这个解决方案的简单性,但我会使用"read -s"作为密码字段.这只是关闭回声,这样当输入密码时,它在提示符下(或在回滚缓冲区中)是不可读的 (3认同)

小智 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" }'
Run Code Online (Sandbox Code Playgroud)

  • 也可以添加编程语言,例如:""language":"python"` (3认同)