How to change the URI (URL) for a remote Git repository?

前端 未结 25 2037
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 00:28

I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved \"origin\" to a NAS and successfully tested cloning it from here.

I would like to

25条回答
  •  抹茶落季
    2020-11-22 01:21

    Navigate to the project root of the local repository and check for existing remotes:

    git remote -v
    

    If your repository is using SSH you will see something like:

    > origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    > origin  git@github.com:USERNAME/REPOSITORY.git (push)
    

    And if your repository is using HTTPS you will see something like:

    > origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    > origin  https://github.com/USERNAME/REPOSITORY.git (push)
    

    Changing the URL is done with git remote set-url. Depending on the output of git remote -v, you can change the URL in the following manner:

    In case of SSH, you can change the URL from REPOSITORY.git to NEW_REPOSITORY.git like:

    $ git remote set-url origin git@github.com:USERNAME/NEW_REPOSITORY.git
    

    And in case of HTTPS, you can change the URL from REPOSITORY.git to NEW_REPOSITORY.git like:

    $ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git
    

    NOTE: If you've changed your GitHub username, you can follow the same process as above to update the change in the username associated with your repository. You would only have to update the USERNAME in the git remote set-url command.

提交回复
热议问题