Is there a way to rename a repository on Bitbucket using their API
Asked Answered
T

5

36

I couldn't find anything even remotely related in the documentation.

Turnip answered 20/2, 2013 at 9:50 Comment(0)
D
18

For version 2.0 of the API:

According to 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}\"}"

Using the PUT method allows renaming of a repository.

For version 1.0 of the API:

According to 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"

This allows to update the visible name of a repository.

Dub answered 20/2, 2013 at 9:57 Comment(1)
Sadly, this does not work for the Server/Datacenter product.Parathion
D
65

Using the Bitbucket website you can rename a repo as follows:

  1. Go to the repo's overview page, usually https://bitbucket.org/username/oldname/overview
  2. Click the settings cog on the far right end of the menu row !
  3. Instead of 1. and 2. you can type 'r' then 'a' for administration.
  4. Change the name in the Name field.
  5. Click Save repository details.

Be advised that changing the name of the repo will change its URL access too. Previously the access was https://[email protected]/username/oldname.git Now, however, the repo's URL/Path will be https://[email protected]/username/newname.git

You can check this by going back to the Overview page, and hovering over the big blue HTTPS button. The bottom of your browser will show that it now points to https://[email protected]/username/newname.git

If you are using SourceTree you can update the remote's URL by highlighting the local repo in SourceTree and then

  1. Click Repository
  2. Click Repository Settings...
  3. Highlight the row containing the remote branch. Usually origin https://[email protected]/username/oldname.git
  4. Click Edit
  5. Update the URL/Path field. Change 'oldname.git' to 'newname.git', leave the rest unchanged. So the full path should be https://[email protected]/username/newname.git
  6. Click OK
Diatessaron answered 17/3, 2014 at 0:1 Comment(2)
If you cannot find the Settings button, currently it is "hidden" in the lower left corner.Choosy
The question is about the API, so although this answer contains useful info, it doesn't answer the questionRenn
D
18

For version 2.0 of the API:

According to 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}\"}"

Using the PUT method allows renaming of a repository.

For version 1.0 of the API:

According to 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"

This allows to update the visible name of a repository.

Dub answered 20/2, 2013 at 9:57 Comment(1)
Sadly, this does not work for the Server/Datacenter product.Parathion
D
4

In a unix shell you can use cURL;

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

Is it possible for a user to authenticate in private repositories, but still have only administrators able to execute:

curl https://USER:[email protected]/1.0/repositories/{accountname}/{old_repo_name} --data "name=new_repo_name" -X PUT
Donn answered 19/4, 2013 at 13:8 Comment(0)
O
1

Just in case anyone hits this with looking for a solution to an old version of the bitbucket API (in my case 5.14.0) to say the documentation on this version is lacking is being quite polite.

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"}'
Obscene answered 19/3, 2021 at 15:25 Comment(2)
Damn. Thank you. Where is this documented? Is this info seen here docs.atlassian.com/bitbucket-server/rest/5.16.0/… ?Livable
Sorry i cant remember how i came upon this command, i think it was lots of trial and errorObscene
P
0

According to the lastest API here is the correct curl command:

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

Note that the repo_slug is the repository name IN LOWER CASE. If you don't put it all in lower case you would get the not so expressive answer "Not Found".

If you are not sure what is the repository slug execute the following command, which shows you the user's information including current repositories, and look for the field "slug"

curl --user username:password https://bitbucket.org/api/1.0/user
Pashto answered 13/6, 2013 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.