How do I rename a repository on GitHub?
Asked Answered
F

12

436

I wanted to rename one of my repositories on GitHub, but I got scared when a big red warning said:

  1. We will not set up any redirects from the old location
  2. You will need to update your local repositories to point to the new location
  3. Renaming may take a few minutes to complete

Does anyone have step-by-step instructions on how to accomplish #1 and #2 manually? Or what do I have to do locally?

Fabric answered 22/4, 2011 at 1:57 Comment(3)
You don't need to update your local reop anymore after a Github repo renaming. See my answer below.Wilhite
On Bitbucket, you go to the repository settings and change the name, and then on your local computer, change it also in the .git/config file.Oliviaolivie
Open Repo -> Settings -> RenameBifoliate
B
469

If you are the only person working on the project, it's not a big problem, because you only have to do #2.

Let's say your username is someuser and your project is called someproject.

Then your project's URL will be1

[email protected]:someuser/someproject.git

If you rename your project, it will change the someproject part of the URL, e.g.

[email protected]:someuser/newprojectname.git

(see footnote if your URL does not look like this).

Your working copy of Git uses this URL when you do a push or pull.

So after you rename your project, you will have to tell your working copy the new URL.

You can do that in two steps:

Firstly, cd to your local Git directory, and find out what remote name(s) refer to that URL:

$ git remote -v
origin  [email protected]:someuser/someproject.git

Then, set the new URL

$ git remote set-url origin [email protected]:someuser/newprojectname.git

Or in older versions of Git, you might need:

$ git remote rm origin
$ git remote add origin [email protected]:someuser/newprojectname.git

(origin is the most common remote name, but it might be called something else.)

But if there are lots of people who are working on your project, they will all need to do the above steps, and maybe you don't even know how to contact them all to tell them. That's what #1 is about.

Further reading:

Footnotes:

1 The exact format of your URL depends on which protocol you are using, e.g.

Beverlee answered 22/4, 2011 at 1:59 Comment(7)
Thanks for your reply! For #1, I do not have any web pages that link to the repo. So I'm safe? For #2, what exactly is happening there? Thanks!Fabric
I have added more information about remotes that should help.Beverlee
My output for git remote -v is in the form [email protected]:someuser, the forward slash you've put here didn't work for me. Everything else here did, though.Tammany
Thanks. Fixed. I still have to find a way to mention https and git URLs.Beverlee
Will this affect the stats of the repo like number of stars?Persephone
For me git remote set-url origin https://github.com/username/newprojectname.git workedDenn
Its better to try this out first with a dummy repository and then do it full fledged on the real repository.Mobocracy
W
184

Note that since May 2013 ("Repository redirects are here!"), you can rename your GitHub repo without breaking any links:

We're happy to announce that starting today, we'll automatically redirect all requests for previous repository locations to their new home in these circumstances. There's nothing special you have to do. Just rename away and we'll take care of the rest.

As a special bonus, we'll also be servicing all Git clone, fetch, and push requests from previous repository locations.

That means you don't even have to git remote set-url (change the url of your remote GitHub repo) on your local cloned repo!
Although Gabriel notes in the comments that the official GitHub help page strongly recommends that you do so:

to reduce confusion, we strongly recommend updating any existing local clones to point to the new repository URL. You can do this by using git remote on the command line:

git remote set-url origin new_url

Beware though:

GitHub Pages sites are not automatically redirected when their repositories are renamed at this time.
Renaming a Pages repository will continue to break any existing links to content hosted on the github.io domain or custom domains.

Plus, the user still owns the namespace: if he/she creates a new repo using the old name of the renamed repo, that redirection (for said renamed repo) will stop working.

Wilhite answered 17/5, 2013 at 5:52 Comment(2)
This is really useful but was initially very confusing when the rename didn't break my old push/pull activity. Now I can change the name immediately and let everyone else know to update their repositories using set-url before certain date. After that date, I'll smash the old name repo by creating a blank one with a nice "I WARNED U" readme file.Decomposer
Note that even though you don't have to use git remote set-url to update an existing local clone to point to the new repository URL, it is strongly recommended that you do.Inearth
M
107

Rename a GitHub repository as follows:

  1. Log in to your http://github.com account.
  2. Browse to the repository to rename.
  3. Click Settings.
  4. Set Repository Name to the new name.
  5. Click Rename.

After this step your online repository matches your local folder name.

You may also want to rename your local folder. Do so manually and use the GitHub client for Windows to find your repository. Rename the local copy and it will match GitHub again.

Maravedi answered 26/1, 2013 at 13:32 Comment(1)
It's amazing how, not only the highly voted answers here but help pages on github.com elide the step of renaming on github.com via the settings tab.Vallo
E
17

The simplest way I found

  1. Go to your repo link for example:- https://github.com/someuser/someRepo.git

  2. Click on setting tab.

enter image description here

the first thing you can see is your repo name, you can edit that.

Note:- If you have cloned repo on local so, change its folder name manually, that's all.

Egesta answered 17/12, 2017 at 11:21 Comment(1)
Same pollux1er's answerGallinule
A
13

I see a lot of positive feedback to responses I don't find accurate/complete at all.

There are two things to have in mind:

  • Remote repository
  • Local copy of the repository

If you haven't cloned your repo in your machine yet, you just need to rename the Github repository and then proceed to clone the repo so you can have a local copy. In order to rename the Github repo, you just need to:

  1. Go to the repository site (i.e https://github.com/userX/repositoryZ).
  2. In the navigation bar, you will see a tab named "Settings". Click on it.
  3. Just edit the current repository name with the desired one and press "Rename".
  4. Clone the repository as usual (i.e git clone https://github.com/userX/repositoryU).

If you already have a local copy of the project, apart from following the steps above, you need to make sure your local repository (root folder) is renamed properly and it's pointing to the right remote url :) link. In order to achieve that, do the following:

  1. You might want to use the new given name for your repo. To do so, rename the local folder either by using the OS GUI(Finder, Windows Explorer, etc.) or console:

mv -R current-repo-name new-repo-name

  1. Change the remote url. From the root of the folder, use the following:

$ git remote set-url origin https://github.com/userX/repositoryU

or

$ git remote set-url origin [email protected]:userX/repositoryU.git

The second step is not mandatory, though. Github announced a while ago that they would redirect all requests from previous repository urls to the assigned ones. That means you don't need to use $ git remote set-url ..., but they still encourage you to do so to avoid confusion.

Hope it helped. If you have any questions or the post is not clear enough, let me know.

Antitragus answered 24/9, 2018 at 19:54 Comment(0)
K
10

This answer is now obsolete! GitHub will forward to new locations now. See this answer for details.


The reason this warning is there is because #1 can't be made manually.

If you are the only person working on and linking to the repository, then you are fine with changing the remote in your local repo and in your webpages.

However, the reason to have a public repository on github in the first place is that you can have others cloning your repository and linking to your github project page.


The old url github.com/<username>/<repository> is owned by github. When they don't setup any redirects to the new url, nobody can. So things will break for everybody except the persons you are telling.

How big of a problem that is, is up to you though. If you have an official project page on a different server, then the github url might not be much of a problem. If you advertised your project with the github url in mailing lists and directories, then you probably should not change the repo name.


An alternative to changing the repo name is to create a new repository and leave notes in the old one (also as commits in the repo) about how to reach your new repo.

If you wan't your new repo to be listed as a fork of your old repo you need to create a new github account. You can add your other account as a collaborator for both repositories.

Koralle answered 19/12, 2012 at 14:52 Comment(0)
P
6

It is worth noting that if you fork a GitHub project and then rename the newly spawned copy, the new name appears in the members network graph of the parent project. The complementary relationship is preserved as well. This should address any reservations associated with the first point in the original question related to redirects, i.e. you can still get here from there, so to speak. I, too, was hesitant because of the irrevocability implied by the warning, so hopefully this will save others that delay.

Philomel answered 30/5, 2012 at 18:7 Comment(3)
You can't fork your own project on github. So you have to use another account, but that would work.Koralle
I forked to an organization, so I guess that's the same as using another account. I'm sure you're correct.Philomel
You can create a new empty repository. Clone the old repository. Add a remote referencing your new repository. And then push the branches you want to the new repository (e.g. master). I guess that would be a partial fork.Symbolic
P
6
  • Navigate to your repository path.
  • Click on setting button which is there in right panne.
  • Replace old repository name to new name.
  • Click on Rename button
Pilgrim answered 14/1, 2015 at 14:46 Comment(0)
U
3

This solution is for those users who use GitHub desktop.

  1. Rename your repository from setting on GitHub.com

  2. Now from your desktop click on sync.

Done.

Uta answered 5/5, 2016 at 17:0 Comment(1)
it's strange that such a basic feature wouldn't be found in the application itselfJonquil
A
1
  1. open this url (https://github.com/) from your browser

  2. Go to repositories at the Right end of the page

  3. Open the link of repository that you want to rename

  4. click Settings (you will find in the Navigation bar)

  5. At the top you will find a box Called (Repository name) where you write the new name

  6. Press Rename

Ascend answered 18/9, 2017 at 11:3 Comment(0)
E
1

I have tried to rename the repository on the web page:

  1. Click on the top of the right pages that it's your avatar.
  2. you can look at the icon of setting, click it and then you can find the Repositories under the Personal setting.
  3. click the Repositories and enter your directories of Repositories, choose the Repository that you want to rename.
  4. Then you will enter the chosen Repository and you will find the icon of setting is added to the top line, just click it and enter the new name then click Rename.

Done, so easy.

Edinburgh answered 27/2, 2019 at 13:35 Comment(0)
L
-4

Simple solution:

1) Open your project url: https://github.com/someuser/project-name
2) in the top, aside of the project name, click EDIT

Libration answered 5/6, 2014 at 7:23 Comment(1)
There is no such buttonOrban

© 2022 - 2024 — McMap. All rights reserved.