What Is A Git Remote?
A remote within the control system Git is a common repository utilized by all users when exchanging changes that have been made. The git remote is essentially a pointer referring to a cloned version of the user’s project that is typically hosted remotely, such as on another network or a remote server. The remote repository is given the shorthand convention ‘origin’, which you may see referenced in the commands.
If you’re working within a group on a project, multiple remotes may be helpful. Remotes can be added, renamed, or removed as desired.
Why You May Want To Remove A Remote
The remote repository can be conveniently hosted by a Git hosting provider, but if the repository is migrated over to another provider, then it’s possible you’ll want to erase the remote URL from within your repository. Of course, if the project is no longer required and you’re no longer using that mirror, or a contributor is no longer contributing, then you may also wish to remove a remote and its associated settings.
Removal of the remote using the command outlined below will delete all configuration settings and remote-tracking branches with which the specified remote is associated.
Check Current Remotes
If you wish to see a list of current remotes, the “git remote” command can be run in the terminal, which will be entered as “$ git remote“. You’ll see the short names of all remote handles and, if you’ve cloned the repository, you’ll see “origin” included in the list. This command will list all remotes, so if you’re working with numerous collaborators and have multiple remotes, you’ll see them all.
If you want to see the URLs stored by Git then you can add “-v“, making the command “$ git remote -v“. This will list allow you to pull the contributions from all users and you may, although you won’t be able to identify this from the list, have push permission on some of them.
To get further information and to inspect any remote, you can use the following command: “git remote show“. This can be run with a short name specified, like “origin”, which will then show the remote repository URL and its tracking branch details. The command will identify that you’ve run “git pull” and that you are within the “master branch”, and it will then merge in the master branch automatically following the remote references being fetched. All remote references pulled will be listed.
Steps For Removing A Remote
This command is to be used within the root folder of the specified repository. Head to the directory where your repository is stored and use the command “git remote remove” or “git remote rm”, followed by the name of the remote to be removed. The command should look like this :
$ git remote remove
$ git remote rm
If the remote is named “production2”, the full command may look something like this :
$ git remote rm production2
This command will remove any entry or reference to the remote repository from within the .git/config file. However, the command won’t remove the repository itself from the server.
Troubleshooting Remote Removal
You might receive an error message when inputting the command in the terminal, such as:
"error: Could not remove config section 'remote.'"
"fatal : No such remote"
These errors suggest that the remote you’ve entered doesn’t exist or has already been removed. Check the spelling and that you’ve entered the command correctly and try again.
Confirming A Remote Has Been Removed
You can double-check that the remote has been removed by checking the current remote connections. Enter the command “$ git remote -v“. The output will display the origin(s) and associated URL(s) present.