Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to replace remote.origin.url in Git?

I'm new to Git. Let's say Alice and Bob had been developing their project by using two Git repositories for each. And, Alice at certain times want to set up a new repository to manage their common progress. Do you think what is the best way to replace remote.origin.url in the configuration of Git?

  • to replace by git config --replace
  • to create new repos by git clone MAIN_REPOS
  • or any?
like image 538
suzukimilanpaak Avatar asked Mar 10 '10 19:03

suzukimilanpaak


People also ask

How do I override git remote origin?

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. Change your remote's URL from HTTPS to SSH with the git remote set-url command. 4th Step:- Now Verify that the remote URL has changed.


2 Answers

If they already have a remote called origin but want the new remote to be called origin then the most logical thing to do is rename or remove the existing remote called origin and add a new one:

git remote rename origin old_origin

git remote add origin url://new/url.git

If you don't care about the old origin you can just reset the URL, but you would probably want to do a full git fetch and a git remote prune origin afterwards for tidiness.

git config remote.origin.url url://new/url.git

If you have a very recent git (>1.7.0), you have a remote sub command for this:

git remote set-url origin url://new/url.git
like image 79
CB Bailey Avatar answered Sep 23 '22 18:09

CB Bailey


Well simply update the url in config file from .git directory.

update git origin

like image 20
user1994 Avatar answered Sep 23 '22 18:09

user1994