How to remove remote origin from a Git repository

GitGit Remote

Git Problem Overview


I just did git init to initialize my folder as Git repository and then added a remote repository using git remote add origin URL. Now I want to remove this git remote add origin and add a new repository git remote add origin new-URL. How can I do it?

Git Solutions


Solution 1 - Git

Instead of removing and re-adding, you can do this:

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

See this question: https://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git

To remove remote use this:

git remote remove origin

Solution 2 - Git

If you insist on deleting it:

git remote remove origin

Or if you have Git version 1.7.10 or older

git remote rm origin

But kahowell's answer is better.

Solution 3 - Git

To remove a remote:

git remote remove origin

To add a remote:

git remote add origin yourRemoteUrl

and finally

git push -u origin master

Solution 4 - Git

you can try this out,if you want to remove origin and then add it:

git remote remove origin

then:

git remote add origin http://your_url_here

Solution 5 - Git

I don't have enough reputation to comment answer of @user1615903, so add this as answer: "git remote remove" does not exist, should use "rm" instead of "remove". So the correct way is:

git remote rm origin

Solution 6 - Git

To remove just use this command

git remote remove origin

Add new

git remote add origin (path)

Solution 7 - Git

You can rename (changing URL of a remote repository) using :

git remote set-url origin new_URL

new_URL can be like https://github.com/abcdefgh/abcd.git

Too permanently delete the remote repository use :

git remote remove origin

Solution 8 - Git

To set a origins remote url-

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

here origin is your push url name. You may have multiple origin. If you have multiple origin replace origin as that name.

For deleting Origin

   git remote rm origin/originName
   or
   git remote remove origin/originName

For adding new origin

   git remote add origin/originName git://new.url.here / RemoteUrl

Solution 9 - Git

perhaps I am late you can use git remote remove origin it will do the job.

Solution 10 - Git

Another method

Cancel local git repository(Warning: This removes the history)

rm -rf .git

Then; Create git repostory again

git init

Then; Repeat the remote repo connect

git remote add origin REPO_URL

A warning though: This removes the history.

Solution 11 - Git

first will change push remote url

git remote set-url --push origin https://newurl

second will change fetch remote url

git remote set-url origin https://newurl

Solution 12 - Git

You can go to the .git folder, edit the config file without using the commands.

Solution 13 - Git

if multiple remotes are set for a project like heroku and own repository then use the below command to check the available remote URLs inside the local project directory

git remote -v

it will display all the remote URLs like

heroku	https://git......git
origin	https://git......git

if you want to remove heroku remote then,

git remote remove heroku

it will remove heroku remote only if want to remove own remote repository

git remote remove origin

Solution 14 - Git

Git aliases has been life saver:

Note: Default name origin if it is different than update according to your needs. I usually have "origin" for all repos

Step-1: Define git aliases ->

This command will help to view your existing "origin" and remote "URL"

 git config --global alias.url "remote -v" 

This will remove your existing remote "origin"

git config --global alias.ro "remote remove origin"

This will add new remote "origin"

git config --global alias.ao "remote add origin"

Step-2: How to use it ->

  • open your terminal having git repo
  • check existing origin/ url by running command
git url

e.g output:

IF-PERSONAL REPO:

git@github.com:<USERNAME>/<REPO-NAME>.git (fetch/push)


IF-ORGANIZATION:

origin  git@github.com:<ORGANIZATION>/<REPO-NAME>.git (fetch/push)

  • Remove existing origin and url by running command
git ro
  • Add new remote origin by running command
git ao <URL>

e.g git ao [email protected]:<USERNAME>/<REPO-NAME>.git 

Solution 15 - Git

If you are here and looking for an easier way to do this using Android Studio. You can:

  1. On the Menu bar go to Git and then click Manages remotes...
  2. A window will open where you can add and remove origin URLs using the (+) and (-) buttons.
  3. Click ok to apply.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOm3gaView Question on Stackoverflow
Solution 1 - GitkahowellView Answer on Stackoverflow
Solution 2 - Git1615903View Answer on Stackoverflow
Solution 3 - GitVonteiView Answer on Stackoverflow
Solution 4 - GitManish KakatiView Answer on Stackoverflow
Solution 5 - GitheroinView Answer on Stackoverflow
Solution 6 - GitsamranView Answer on Stackoverflow
Solution 7 - GitAnshul BishtView Answer on Stackoverflow
Solution 8 - GitNasir KhanView Answer on Stackoverflow
Solution 9 - GitKrishna KamalView Answer on Stackoverflow
Solution 10 - GitYasin UYSALView Answer on Stackoverflow
Solution 11 - GitHamit YILDIRIMView Answer on Stackoverflow
Solution 12 - GitShusen YiView Answer on Stackoverflow
Solution 13 - GitMohamed Saheed Mohamed RiswanView Answer on Stackoverflow
Solution 14 - GitkhizerView Answer on Stackoverflow
Solution 15 - GitGrimmretView Answer on Stackoverflow