How to Remove a Git Remote From Repository

November 17, 2020

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 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 folder


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

Checking 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 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 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
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to Delete a Git Branch Remotely and Locally
October 13, 2020

This article provides a quick overview of basic commands and processes necessary for deleting both local and...
Read more
How To Unstage Files on Git
September 15, 2020

Unstaging in Git means removing queued changes from the index. This guide covers several different ways to...
Read more
Git Commands Cheat Sheet
March 10, 2020

Git, the popular version control system, has a plethora of commands for managing your project history.
Read more
How To Switch Branch on Git
February 3, 2020

Developers need to switch between branches frequently. Git branches allow you to work on your code, fix bugs...
Read more