GLM 4.5 Air

How to Change Git Remote URL: Complete Guide

Step-by-step tutorial on changing Git remote URL from USB to NAS. Preserve commit history and avoid conflicts when updating repository location.

Question

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

I have a repository (origin) originally stored on a USB key that I cloned to my local machine. I’ve moved the origin repository to a NAS and successfully tested cloning from there. I want to update my local repository to pull from the NAS instead of the USB key.

What is the proper way to change the URI of the ‘origin’ remote in my local Git repository? I’m considering two approaches:

  1. Push all commits to the USB origin and then copy it to the NAS again (though this seems inefficient as I’ve already made new commits to the NAS)
  2. Add a new remote to my local repository and delete the old one (but I’m concerned about breaking my commit history)

What is the recommended method to update the remote repository URL without losing commit history or causing conflicts?