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

前端 未结 25 2065
爱一瞬间的悲伤
爱一瞬间的悲伤 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:19

    If you're using TortoiseGit then follow the below steps:

    1. Go to your local checkout folder and right click to go to TortoiseGit -> Settings
    2. In the left pane choose Git -> Remote
    3. In the right pane choose origin
    4. Now change the URL text box value to where ever your new remote repository is

    Your branch and all your local commits will remain intact and you can keep working as you were before.

    0 讨论(0)
  • 2020-11-22 01:20

    As seen here,

    $ git remote rm origin
    $ git remote add origin git@github.com:aplikacjainfo/proj1.git
    $ git config master.remote origin
    $ git config master.merge refs/heads/master
    
    0 讨论(0)
  • 2020-11-22 01:21

    Troubleshooting :

    You may encounter these errors when trying to changing a remote. No such remote '[name]'

    This error means that the remote you tried to change doesn't exist:

    git remote set-url sofake https://github.com/octocat/Spoon-Knife fatal: No such remote 'sofake'

    Check that you've correctly typed the remote name.

    Reference : https://help.github.com/articles/changing-a-remote-s-url/

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 01:22

    check your privilege

    in my case i need to check my username

    i have two or three repository with seperate credentials.

    problem is my permission i have two private git server and repositories

    this second account is admin of that new repo and first one is my default user account and i should grant permission to first

    0 讨论(0)
  • 2020-11-22 01:23

    In the Git Bash, enter the command:

    git remote set-url origin https://NewRepoLink.git

    Enter the Credentials

    Done

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