使用Bitbucket的API能否重命名存储库?

36

在文档中,我甚至找不到任何相关的内容。

5个回答

65
使用Bitbucket网站,您可以按如下方式重命名repo:
  1. 进入repo的概述页面,通常为https://bitbucket.org/username/oldname/overview
  2. 单击菜单栏最右侧的设置齿轮图标!
  3. 您也可以输入'r',然后输入'a'进行管理,而不是使用1和2。
  4. Name字段中更改名称。
  5. 单击Save repository details.
请注意,更改repo的名称将同时更改其URL访问路径。以前的访问路径为https://username@bitbucket.org/username/oldname.git现在,repo的URL / Path将为https://username@bitbucket.org/username/newname.git 您可以通过返回概述页面并将鼠标悬停在大蓝色HTTPS按钮上来检查这一点。您的浏览器底部将显示它现在指向https://username@bitbucket.org/username/newname.git 如果您正在使用SourceTree,则可以通过在SourceTree中突出显示本地repo,然后执行以下操作来更新远程URL:
  1. 单击Repository
  2. 单击Repository Settings...
  3. 突出显示包含远程分支的行,通常为origin https://username@bitbucket.org/username/oldname.git
  4. 单击Edit
  5. 更新URL / Path字段。将'oldname.git'更改为'newname.git',其余内容保持不变。因此,完整路径应为https://username@bitbucket.org/username/newname.git
  6. 单击OK

8
如果您找不到设置按钮,目前它被“隐藏”在左下角。 - arni
6
问题涉及API,因此尽管这个答案包含了有用的信息,但它并没有回答问题。 - Greg Woods

18

对于 API 的版本 2.0:

根据https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-put的说明。

PUT https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug} --data "{\"name\": \"${new_name}\"}"

使用PUT方法可以重命名存储库。

API版本1.0:

根据https://confluence.atlassian.com/display/BITBUCKET/repository+Resource+1.0

PUT https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug} --data "name=new name"

这允许更新存储库的可见名称。


很遗憾,这对于服务器/数据中心产品不起作用。 - Marakai

4

在Unix shell中,您可以使用cURL:

curl https://api.bitbucket.org/1.0/repositories/{accountname}/{old_repo_name} --data "name=new_repo_name" -X PUT

用户是否可以在私有存储库中进行身份验证,但仅允许管理员执行:

curl https://USER:PASS@api.bitbucket.org/1.0/repositories/{accountname}/{old_repo_name} --data "name=new_repo_name" -X PUT

1

万一有人因为旧版本的Bitbucket API(在我这里是5.14.0)而寻找解决方案,需要指出的是,这个版本的文档缺失非常严重。

curl --location --request PUT 'https://git.local.install/rest/api/1.0/projects/aa/repos/my-repo' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic .....' \ 
--data-raw '{"name":"my-new-name"}'

该死。谢谢。这个在哪里有记录?这个信息在这里看到了吗 https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8287362016 ? - José Cabo
抱歉,我记不得是怎么获得这个命令的了,我想那可能是大量尝试和错误的结果。 - Damo

0

根据最新的API,这是正确的curl命令:

curl -X PUT --user username:password https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}  --data "name=newRepoName"

请注意,repo_slug 是小写的仓库名称。如果您没有全部使用小写字母,则会得到不太明确的答案“未找到”。
如果您不确定仓库 slug 是什么,请执行以下命令,它将显示用户信息,包括当前仓库,并查找“slug”字段。
curl --user username:password https://bitbucket.org/api/1.0/user

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接