Easiest way to rename git project configured on BitBucket
Asked Answered
G

5

91

I have a project hosted on BitBucket

Can I rename it ?

If not and I need to create a new repository can someone tell me the easiest way to do that and have new repo on BitBucket (one particular cause of confusion for me is whether to drive the process locally or from the bitbucket website)

Update

Thankyou Rafal I've followed your instructions and it works great but Im just going to make it a little clearer for noobies like myself (on linux)

  1. In Bitbucket project settings rename project
  2. vi projectname/.git/config and edit url value to reflect new bitbucket repository url
  3. mv projectname newprojectname
Gunsmith answered 26/8, 2014 at 14:10 Comment(3)
Is the third step mandatory?Brewhouse
@Brewhouse it appears not but it seems to me it could be needlessly confusing in the future if I dont do this because if I have renamed the bitbucket repos but then when I look for my checked out copy on linux I cant find it because the name is different because I didnt rename it.Gunsmith
WARNING for anyone attempting this: renaming a repo also changes its URL which will break the environments for anyone working on the repo, and potentially package managers, CDNs and build/deploy tools that pull from the repo. In each case you/they will need to update the URL for the repo. For some reason BitBucket provide no warning about this. Do this with care.Centre
U
104

You can rename the project form the settings menu of the projects on Bitbucket.

Once you rename it, you need to update your git config file to fetch the data from the new location

nano .git/config

Change the name of the project to the new name and save

Unit answered 26/8, 2014 at 14:13 Comment(3)
Thankyou I've followed your instructions and it works great but Im just going to make it a little clearer for noobies like myself (on linux)Gunsmith
Cool, btw mv projectname newprojectname is optional as the name of the git repository and the name of your local folders are irrelevant and don't need to matchUnit
just to clarify, you would change the name in the URL for the [remote "origin"] branchBrnaba
O
32

I think this is the easiest way:

  1. Rename your project from the bitbucket settings menu
  2. Clone your newly re-named project
    • git clone new_url

This works because git is a distributed version control system. As far as git is concerned there is nothing special about the existing repo on your computer. Just clone a new one.

If you prefer to keep using the existing local repo in my opinion it's easier to use git to update itself instead of manually editing a config file:

  1. Rename your project from the bitbucket settings menu
  2. Change directory into your local project and update git to fetch data from the newly renamed repo
    • git remote set-url origin new_url
  3. Optionally (git doesn't care) rename your local project directory
    • mv projectname newprojectname
Orose answered 1/8, 2015 at 5:42 Comment(1)
This is true only if all stuff from the local repo have been pushed to the remote repo. For instance, I have stuff on my local repo I don't really want to push yet, or just want to keep it to me for archival. So, be sure to push all you need to keep if you do it that way!Quaquaversal
H
9

You can also do it in the BitBucket website.

In your project page (https://bitbucket.org/username/yourproject), go to settings, repository details and then change the name and save it.

Hob answered 26/8, 2014 at 17:24 Comment(2)
You need to be admin to have access to settingMarek
How does this affect the team working on the project on using local branches?Ubangi
S
7

To rename your bitbucket repo you can do 2 simple actions:

  1. Rename your repository name in bitbucket repository settings(Your repository>Settings>Name field)
  2. (In case if you have the repository cloned to local machines) In project root directory go to .git folder, then open config file. Change all the old repo names to new repo one.

enter image description here

Sonnie answered 28/3, 2020 at 14:54 Comment(0)
M
1

Want to toss this out on this thread since I'm not seeing it, but Bitbucket will keep track of previous names the repository had... so if you want renaming to break builds... it won't.

ie. create repo named test_repo checkout test_repo rename test_repo repo in Bitbucket interface (zz_test_repo) you will still be able to create a change and commit and continue like nothing happened with the test_repo

I don't like this "feature", but it is what it is, sadly.

Mandorla answered 30/6, 2022 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.