giturlgit-remote

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


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 know if I can change the URI of "origin" in the settings of "local" so it will now pull from the NAS, and not from the USB key.

For now, I can see two solutions:


Solution

  • First, view the existing remotes to verify which URL is currently set:

    git remote -v
    

    Then, you can set it with:

    git remote set-url origin <NEW_GIT_URL_HERE>
    

    See git help remote. You also can edit .git/config and change the URLs there.

    You're not in any danger of losing history unless you do something very silly (and if you're worried, just make a copy of your repo, since your repo is your history.)