Introduction
A git remote is a connection to a repository hosted on a remote server – GitHub, BitBucket, GitLab or any other remote location. If you collaborate with a team on a larger project, it is often useful to create more than one git remote.
However, as the project progresses, the remote repository may move to another host or a member of the team may stop working on the project. The particular remote is then no longer needed.
In this tutorial you will you will learn how to remove a git remote from your repository.
Prerequisites
- Access to the command line
- A Git project
- Git installed and configured (See our guides on Installing Git on Windows, Installing Git on Mac, How to Install Git on Ubuntu, and How to Install Git on CentOS)
Option 1: Remove a Git Remote Using Command Line
1. To delete a git remote using the command line, first cd
into the directory of the repository which contains the remote:
2. To list the available remotes and their URLs in the folder, type git remote -v
:
3. Delete a remote with the following command:
git remote remove [remote name]
4. The command will not give you any feedback. Use git remote -v
to confirm the removal:
Note: If you are using Git version 1.7.10 or older, use git remote rm [remote name]
.
Option 2: Remove a Git Remote by Editing the Configuration File
The git remote remove
command does not delete the repository. Instead, it removes entries about the remote from the .git/config file.
Using the command line is the recommended way of removing a remote. However, you can also remove it by editing the .git/config configuration file.
1. To do this, open the file in a text editor (we’ll be using Vim):
vi .git/config
2. Search the file for the entry belonging to the remote you wish to remove.
3. Delete the entry, then save the file and exit.
Remove the origin Remote
Origin is often the only remote you see in a project. It is the default pointer to the repository you cloned.
If you wish to remove the origin remote, use the same git remote remove
command:
git remote remove origin
Conclusion
This article explained how to remove a git remote repository from your machine, using the command line or by editing the .git/config file.
You might also be interested in learning how to delete a remote or local Git branch or download a copy of our free Git Cheat Sheet.
原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/223857.html