Friday, November 15, 2024
Google search engine
HomeGuest BlogsHow to Remove a Git Remote From Repository

How to Remove a Git Remote From Repository

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.

How to Remove a Git RemoteHow to Remove a Git Remote

Prerequisites

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:

Navigating to the git repository folderNavigating to the git repository folder

2. To list the available remotes and their URLs in the folder, type git remote -v:

Checking the list of remotesChecking the list of remotes

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:

Confirming the removal of the remoteConfirming the removal of the remote

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.

Removing remotes by editing the git configuration fileRemoving remotes by editing the git configuration file

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.

Was this article helpful?
YesNo

RELATED ARTICLES

Most Popular

Recent Comments