Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 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:

  • push everything to the usb-orign, and copy it to the NAS again (implies a lot of work due to new commits to nas-origin);

  • add a new remote to "local" and delete the old one (I fear I'll break my history).

like image 959
e-satis Avatar asked Mar 12 '10 12:03

e-satis


People also ask

How do I change my push URL?

Run the git remote set-url --add --push origin git-repository-name command where git-repository-name is the URL and name of the Git repository where you want to host your code. This changes the push destination of origin to that Git repository.


2 Answers

You can

git remote set-url origin new.git.url/here 

(see git help remote) or you 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.)

like image 101
hobbs Avatar answered Oct 09 '22 22:10

hobbs


git remote -v # View existing remotes # origin  https://github.com/user/repo.git (fetch) # origin  https://github.com/user/repo.git (push)  git remote set-url origin https://github.com/user/repo2.git # Change the 'origin' remote's URL  git remote -v # Verify new remote URL # origin  https://github.com/user/repo2.git (fetch) # origin  https://github.com/user/repo2.git (push) 

Changing a remote's URL

like image 41
Utensil Avatar answered Oct 09 '22 22:10

Utensil