I initially cloned a Git repo from a USB drive, but I’ve since moved the origin to a NAS.
Now, I want to update my local repository to use the NAS as the new remote source. What’s the safest way to git change remote URL without affecting commit history or pushing everything manually again?
You can safely update the remote URL using this command:
git remote set-url origin <new-URL>
I’ve done this many times when moving between local, staging, or production remotes. It doesn’t affect your commit history at all, just tells Git where to fetch/push from now. You can verify it worked with git remote -v
.
Yep, I’ve had to do this when migrating repos to internal GitLab servers.
Just like Anna said, git remote set-url
is your friend. No need to delete or re-clone anything. And to be extra sure, I usually run git fetch right after updating the URL to confirm it’s pulling from the new source properly.