How do I rename a repository on GitHub?

前端 未结 12 1608
无人及你
无人及你 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 18:00

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

提交回复
热议问题