Remote Git repositories, also known as Git remotes, are pointers that refer to a copy of said repository usually hosted on another server. By default, you’ll have one remote called origin, and as you add different features and environments, it’ll divide into branches.
However, multiple Git remotes do come in handy when collaborating with multiple people on the same project. If a remote repository moves to another host or stops being active, you might want to remove the related remote.
How to remove a Git remote?
Removing a Git remote is actually rather simple. You can do it in one of the following two ways.
It’s recomended that you use the git remote rm command.
Using the git remote rm command
The basic syntax for the command is as follows.
git remote rm [remote name]
Make sure to navigate to the directory where your remote is saved before executing the command. If you want to remove a remote named RepoTest here’s how the command will look like.
git remote rm RepoTest
Note that the command only removes all references to the remote repository and doesn’t actually delete the repository from the server. If you want to verify whether or not the repository was actually remvoed, use the git remote command to list all remote connections.
git remote -v
Also read: How to remove untracked files in Git?
Using the .git/config file
You can also remove a remote repository by using the ..git/config file. After all, all the git remote rm command does is removing entries about the remote repository from the file itself. However, it’s not recommended that you make changes to the file unless you’re absolutely sure of what you’re doing.
In order to remove a remote repository from the file, simply delete all references of the remote from the file itself and save your changes. If you’ve done it right, all references to the remote repository should be deleted.