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

ID : 121259

viewed : 38

Tags : giturlgit-remotegit

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

vote vote


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.)

vote vote


git remote -v # View existing remotes # origin (fetch) # origin (push)  git remote set-url origin # Change the 'origin' remote's URL  git remote -v # Verify new remote URL # origin (fetch) # origin (push) 

Changing a remote's URL

vote vote


git remote set-url {name} {url}

git remote set-url origin 
vote vote


Change Host for a Git Origin Server


Hopefully this isn’t something you need to do. The server that I’ve been using to collaborate on a few git projects with had the domain name expire. This meant finding a way of migrating the local repositories to get back in sync.

Update: Thanks to @mawolf for pointing out there is an easy way with recent git versions (post Feb, 2010):

git remote set-url origin ssh:// 

See the man page for details.

If you’re on an older version, then try this:

As a caveat, this works only as it is the same server, just with different names.

Assuming that the new hostname is, and the old one was, the change is quite simple.

Edit the .git/config file in your working directory. You should see something like:

[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = ssh:// 

Change to, save the file and you’re done.

From my limited testing (git pull origin; git push origin; gitx) everything seems in order. And yes, I know it is bad form to mess with git internals.

vote vote


Switching remote URLs

Open Terminal.

Ist Step:- Change the current working directory to your local project.

2nd Step:- List your existing remotes in order to get the name of the remote you want to change.

git remote -v

origin (fetch)  origin (push) 

Change your remote's URL from HTTPS to SSH with the git remote set-url command.

3rd Step:- git remote set-url origin

4th Step:- Now Verify that the remote URL has changed.

git remote -v Verify new remote URL

origin (fetch) origin (push) 

Top 3 video Explaining How to change the URI (URL) for a remote Git repository?