By e-satis

2010-03-12 12:48:47 8 Comments

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


@Chetabahana 2019-05-25 11:54:35

Change remote git URI to [email protected] rather than

git remote set-url origin [email protected]:<username>/<repo>.git

The benefit is that you may do git push automatically when you use ssh-agent :


# Check ssh connection
ssh-add -l &>/dev/null
[[ "$?" == 2 ]] && eval `ssh-agent`
ssh-add -l &>/dev/null
[[ "$?" == 1 ]] && expect $HOME/.ssh/agent

# Send git commands to push
git add . && git commit -m "your commit" && git push -u origin master

Put a script file $HOME/.ssh/agent to let it runs ssh-add using expect as below:

#!/usr/bin/expect -f
set HOME $env(HOME)
spawn ssh-add $HOME/.ssh/id_rsa
expect "Enter passphrase for $HOME/.ssh/id_rsa:"
send "<my_passphrase>\n";
expect "Identity added: $HOME/.ssh/id_rsa ($HOME/.ssh/id_rsa)"

@Przemek Struciński 2019-04-02 13:37:29

You have a lot of ways to do that:


git remote set-url origin [Here new url] 

Just be sure that you've opened it in a place where a repository is.


It is placed in .git/config (same folder as repository)

    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = [Here new url]  <------------------------------------


Step 1 - open settings

Step 2 - change url

Then just edit URL.


  1. Click on the "Settings" button on the toolbar to open the Repository Settings window.

  2. Click "Add" to add a remote repository path to the repository. A "Remote details" window will open.

  3. Enter a name for the remote path.

  4. Enter the URL/Path for the remote repository

  5. Enter the username for the hosting service for the remote repository.

  6. Click 'OK' to add the remote path.

  7. Back on the Repository Settings window, click 'OK'. The new remote path should be added on the repository now.

  8. If you need to edit an already added remote path, just click the 'Edit' button. You should be directed to the "Remote details" window where you can edit the details (URL/Path/Host Type) of the remote path.

  9. To remove a remote repository path, click the 'Remove' button

enter image description here

enter image description here

ref. Support

@VIKAS KOHLI 2017-12-08 11:01:32

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 [email protected]:USERNAME/REPOSITORY.git

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

git remote -v Verify new remote URL

origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
origin  [email protected]:USERNAME/REPOSITORY.git (push)

@Sledge 2019-02-27 20:17:19

Do you have to remove the old origin before you add the new origin?

@VIKAS KOHLI 2019-02-28 07:56:35

I didn't remove from the project anything. I simply do the above steps and it worked

@hobbs 2010-03-12 12:55:50

You can

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

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

@sobi3ch 2013-07-01 07:49:29

If you have a different shell user then maybe you want to specify your git user in the beginning of the new url e.g.: [email protected]://

@kelorek 2013-08-13 18:06:59

You may also want to set the master upstream branch for your new origin location with: git branch -u origin/master. This will allow you to just git push instead of having to git push origin master every time.

@hobbs 2013-08-14 19:38:01

@kelorek or you can just git push -u origin master the first time :)

@Alejandro Moreno 2013-09-18 09:15:26

you'll probably have to do a git pull to merge contents after that:…

@jpillora 2014-06-02 09:12:12

I also had to git remote set-url --push origin git://... in order to set the origin ... (push) url.

@Anil 2016-07-22 23:03:19

use https:// instead of git://

@Michael 2017-07-03 19:16:59

This gives a warning that remote.origin.url has multiple values ... how do i get rid of the old value?

@Ben 2018-01-14 16:11:32

For multiple branches, you can use git push -u --all to push all branches at once to new url (instead of git push -u origin master)

@Mitesh Ukate 2018-08-31 09:51:27

In the case of ssh, you will get the URL in your repo. You have to use exactly the same, unless that it doesn't work. expl: [email protected]:reponame.git

@Syed Priom 2018-12-14 18:14:15

git:// part is not mandatory.

@mauriii 2019-01-03 07:29:38

I always find myself coming back to this and making the same mistake. This is a very old post without edits and this may have been required before, but the "git://" is unnecessary now (and actually doesn't work). I'd suggest changing "git://" to something more obvious such as "[NEW URL]," because this seems to be confusing others as well considering upvotes on newer comment.

@Anupam Maurya 2018-12-18 05:22:28

To check git remote connection:

git remote -v

Now, set the local repository to remote git:

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

Now to make it upstream or push use following code:

git push --set-upstream origin master -f

@Anupam Maurya 2018-12-18 08:15:03

Thanks for your reply, Ishita. I will mark your words...

@OoDeLally 2019-01-28 12:58:03

I was pushing and yet github didn't show my new branch. That last --set-upstream made it work.

@Amitesh 2018-10-15 06:16:47

enter image description here

Troubleshooting :

You may encounter these errors when trying to changing a remote. No such remote '[name]'

This error means that the remote you tried to change doesn't exist:

git remote set-url sofake fatal: No such remote 'sofake'

Check that you've correctly typed the remote name.

Reference :

@Diego Santa Cruz Mendezú 2018-05-06 18:24:43

I worked:

git remote set-url origin <project>

@Vipul bhojwani 2017-08-20 15:14:55

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.

@Chinthaka Devinda 2018-02-21 10:19:00

Best Answer thanks

@Mohideen bin Mohammed 2017-07-31 07:33:37

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

@devDeejay 2017-04-25 09:48:25

In the Git Bash, enter the command:

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

Enter the Credentials


@bong jae choe 2015-12-28 04:53:35

git remote set-url {name} {url}

ex) git remote set-url origin

@Sunil Chaudhary 2016-06-24 11:10:54

  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

@Zaz 2015-04-26 23:13:21

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

@octopusgrabbus 2015-09-15 13:55:48

I could not set the new origin by editing .git/config. It said the git repository named in the URL wasn't a git repository. Once I removed and re-created origin, all was well. I had not looked up git remote set-url as a solution to my problem, though.

@Utensil 2013-10-10 14:43:44

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

@yoda 2011-02-15 02:52:36

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.

@Jesse Chisholm 2016-10-20 15:41:55

Bad form? Perhaps. But if you need to do something the authors didn't expect anyone would ever need to do, then sometimes messing with the internals is required. But you do have to be willing to accept the consequences if you get it wrong. Backup your local repository _before_ messing with git internals.

Related Questions

Sponsored Content

39 Answered Questions

[SOLVED] How do I delete a Git branch locally and remotely?

35 Answered Questions

[SOLVED] How do I discard unstaged changes in Git?

  • 2008-09-09 19:33:59
  • Readonly
  • 2351998 View
  • 4452 Score
  • 35 Answer
  • Tags:   git version-control

29 Answered Questions

[SOLVED] Git fetch remote branch

33 Answered Questions

[SOLVED] How do I undo 'git add' before commit?

41 Answered Questions

[SOLVED] How do I revert a Git repository to a previous commit?

13 Answered Questions

80 Answered Questions

[SOLVED] How do I undo the most recent local commits in Git?

32 Answered Questions

[SOLVED] How do I rename a local Git branch?

  • 2011-07-06 03:20:36
  • Forrest
  • 2592655 View
  • 7864 Score
  • 32 Answer
  • Tags:   git git-branch

21 Answered Questions

27 Answered Questions

[SOLVED] How do I check out a remote Git branch?

Sponsored Content