How to remove a Git remote
By Flavio Copes
Learn how to remove a Git remote with git remote rm origin, after listing your remotes with git remote -v, so you can connect the repo to a new origin.
To remove a Git remote, run git remote rm origin (replace origin with the name of the remote you want to remove). You can list your remotes first with git remote -v to check the name.
Here’s the situation where I needed this. I wanted to create an exact copy of an existing website, and put it in a subdomain, as an archive.
Now this site is under version control, and I wanted to retain the Git history but also deploy it to a new GitHub repo, so I could deploy it separately, now both sites could go on their own destiny.
The website is a Hugo site, so I just copied the website folder into a separate folder, and that was it, locally.
The copied folder still pointed to the original repository, because the .git folder came along with the copy. Time to disconnect it.
List the remotes first
I went into the copied site folder in the terminal, and I ran:
git remote -v
This listed the existing GitHub repository as the “origin” remote, once for fetch and once for push.
Remove the remote
I ran:
git remote rm origin
This removed the origin remote, so running git remote -v didn’t return anything any more.
git remote remove origin does the same thing. rm and remove are two names for the same command.
Note that this only touches your local repository configuration. Nothing gets deleted on GitHub. The commits and branches on the server stay exactly where they are.
Git also removes the remote-tracking branches for that remote, like origin/main, along with any configuration settings tied to it.
Connect a new remote
Now since I use GitHub Desktop I just dragged the folder in that app, and I was able to create a new, different GitHub repository from there.
You can do the same from the terminal. Create an empty repository on GitHub, then add it as the new origin:
git remote add origin git@github.com:flaviocopes/site-archive.git
One pitfall: after removing the remote, a plain git push fails, because Git no longer knows where to push. Once you add the new origin, push with the -u flag the first time:
git push -u origin main
The -u flag links your local branch to the new remote, so future git push and git pull commands work without arguments.