Query explained:
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).
How to change the URL for a remote Git repository? Answer #1:
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.)
Change remote’s URL in git- Answer #2:
You can do this by using the git commands below:
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)
Answer #3:
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.
There is an easy way with recent git versions (post Feb, 2010):
git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git
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 newhost.com
, and the old one was oldhost.com
, 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://oldhost.com/usr/local/gitroot/myproject.git
Change oldhost.com
to newhost.com
, 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.
Answer #4:
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
Answer #5:
I hope you’ve already got your answer, but still this is something that might help you.
git remote set-url {name} {url}
git remote set-url origin
Answer #6:
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 git@github.com:USERNAME/REPOSITORY.git
4th Step:– Now Verify that the remote URL has changed.
git remote -v
Verify new remote URL
origin git@github.com:USERNAME/REPOSITORY.git (fetch)
origin git@github.com:USERNAME/REPOSITORY.git (push)
Answer #7:
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 make change in it,
git remote set-url origin https://pages.github.com/
here,
origin – your branch
if you want to overwrite an existing branch you can still use it.. it will override your existing … it will do,
git remote remove url
and
git remote add origin url
Hope you learned something from this post.
Follow Programming Articles for more!