有没有办法使用他们的API重命名Bitbucket上的存储库

时间:2013-02-20 09:50:50

标签: bitbucket bitbucket-api

是否可以使用其REST API重命名Bitbucket上的现有存储库? 我阅读了Bitbucket API的完整文档,但我找不到任何与远程相关的内容。 我问或许我确实错过了什么。谢谢!

6 个答案:

答案 0 :(得分:65)

使用Bitbucket网站,您可以按如下方式重命名回购:

  1. 转到repo的概述页面,通常是https://bitbucket.org/username/oldname/overview
  2. 点击菜单行最右端的设置cog!
  3. 而不是1.和2.您可以键入'r',然后键入'a'进行管理。
  4. 更改Name字段中的名称。
  5. 点击Save repository details.
  6. 请注意,更改仓库的名称也会更改其URL访问权限。以前访问权限为https://username@bitbucket.org/username/oldname.git但是,现在,回购邮件的网址/路径将为https://username@bitbucket.org/username/newname.git

    您可以返回“概述”页面,然后将鼠标悬停在蓝色的大蓝色按钮上进行检查。浏览器底部会显示它现在指向https://username@bitbucket.org/username/newname.git

    如果您使用的是SourceTree,则可以通过突出显示SourceTree中的本地仓库来更新远程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

答案 1 :(得分:11)

根据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"

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

答案 2 :(得分: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

答案 3 :(得分:1)

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

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

请注意,repo_slug是存储库名称IN LOWER CASE。如果你不把它全部放在小写的情况下你会得到不那么富有表现力的答案“Not Found”。

如果您不确定什么是存储库slug,请执行以下命令,该命令显示用户的信息,包括当前存储库,并查找字段“slug”

curl --user username:password https://bitbucket.org/api/1.0/user

答案 4 :(得分:0)

除了API之外,还可以通过网站手动完成此操作

您可以转到存储库设置

enter image description here

然后更新存储库的名称

enter image description here

请记住,更新存储库名称也会更改存储库的克隆URL 因此,您和使用此存储库的任何人都必须更新远程URL

git remote -v
# View existing remotes

git remote set-url origin https://NewRepoLink.git
# Change the 'origin' remote's URL
# NewRepoLink.git can have this (or similar) form:
# https://[user-name]@bitbucket.org/[team-name]/[repository-name].git

git remote -v
# Verify new remote URL

您还可以看到 Bitbucket官方网站Renaming a repository

  

存储库重命名操作将立即执行,不需要任何后续操作,例如重新编制索引。

答案 5 :(得分:0)

以防万一有人在寻找旧版本的 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"}'
相关问题