How do I rename a repository on GitHub?

前端 未结 12 1514
无人及你
无人及你 2020-11-28 17:13

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 o
相关标签:
12条回答
  • 2020-11-28 17:40

    The simplest way I found

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

    2. Click on setting tab.

    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.

    0 讨论(0)
  • 2020-11-28 17:43

    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

    git@github.com:someuser/someproject.git
    

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

    git@github.com: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  git@github.com:someuser/someproject.git
    

    Then, set the new URL

    $ git remote set-url origin git@github.com:someuser/newprojectname.git
    

    Or in older versions of Git, you might need:

    $ git remote rm origin
    $ git remote add origin git@github.com: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 = git@github.com:someuser/someproject.git
    • HTTPS = https://someuser@github.com/someuser/someproject.git
    • GIT = git://github.com/someuser/someproject.git
    0 讨论(0)
  • 2020-11-28 17:44

    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.

    0 讨论(0)
  • 2020-11-28 17:47

    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.

    0 讨论(0)
  • 2020-11-28 17:47

    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.

    0 讨论(0)
  • 2020-11-28 17:48
    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

    0 讨论(0)
提交回复
热议问题