How do I rename a repository on GitHub?
Solution 1:
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:
- GitHub - working with remotes
- Git Reference - remotes
- Git Book - Distributed Workflows
Footnotes:
1 The exact format of your URL depends on which protocol you are using, e.g.
- SSH = [email protected]:someuser/someproject.git
- HTTPS = https://[email protected]/someuser/someproject.git
- GIT = git://github.com/someuser/someproject.git
Solution 2:
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 thegithub.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.