Change the URI (URL) for a remote Git repository

0 votes
asked Mar 12, 2010 by e-satis

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

9 Answers

0 votes
answered Mar 12, 2010 by hobbs

You can

git remote set-url origin git://

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

0 votes
answered Mar 15, 2011 by yoda

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.

0 votes
answered Mar 10, 2013 by utensil
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

0 votes
answered Jan 26, 2015 by zaz
git remote set-url origin git://new.location

(alternatively, open .git/config, look for [remote "origin"], and edit the url = line.

You can check it worked by examining the remotes:

git remote -v
# origin  git://new.location (fetch)
# origin  git://new.location (push)

Next time you push, you'll have to specify the new upstream branch, e.g.:

git push -u origin master

See also: GitHub: Changing a remote's URL

0 votes
answered Jan 28, 2015 by bong-jae-choe

git remote set-url {name} {url}

ex) git remote set-url origin

0 votes
answered Jan 24, 2016 by sunil-chaudhary
  1. remove origin using command on gitbash git remote rm origin
  2. And now add new Origin using gitbash git remote add origin (Copy HTTP URL from your project repository in bit bucket) done
0 votes
answered Sep 15, 2017 by vipul-bhojwani

If you're using TortoiseGit then follow the below steps:

  1. Go to your local checkout folder and right click to go to TortoiseGit -> Settings
  2. In the left pane choose Git -> Remote
  3. In the right pane choose origin
  4. Now change the URL text box value to where ever your new remote repository is

Your branch and all your local commits will remain intact and you can keep working as you were before.

0 votes
answered Sep 15, 2017 by mohideen-ibn-mohamme

if you cloned your local will automatically consist,

remote URL where it gets cloned.

you can check it using git remote -v

if you want to made change in it,

git remote set-url origin


origin - your branch

if you want to overwrite existing branch you can still use it.. it will override your existing ... it will do,

git remote remove url
git remote add origin url

for you...

0 votes
answered Sep 15, 2017 by deejay

In the Git Bash, enter the command:

git remote set-url origin https://NewRepoLink.git

Enter the Credentials


Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter