How to Remove a Git Remote
Have you set the wrong remote for a Git repository? Do you need to change your remote? Not to worry, Git has you covered. In Git, there’s a command called
git remote remove that you can use to remove a remote from a repository.
This guide will cover everything you need to know about removing a git remote using git remote remove. We’ll walk through an example to help you get started using this command.
What is a Git Remote?
Git remote is a reference that points to the remote version of a Git repository.
Remember, Git is a distributed version control system. This means that you can download a copy of a Git repository on your local machine and make changes. These changes will be independent of the main copy of a repository – the remote copy – until you “push” them to the remote repository.
For the most part, you’ll have one remote branch which is named
origin. When you start a GitHub repository, for example, the instructions you’ll be given ask you to set up a remote named origin. You can change it, but
origin is the default value.
To add a git remote to a local repository, you can use the git remote add command.
With that said, you may need to change your remote at some point. That’s where the git remove remote command comes in handy.
How to Remove a Git Remote
Let’s remove a Git remote from a repository! To start, move to the directory in which your repository is stored. Then execute the following command:
git remote remove [name of the remote]
To delete the
origin remote from your repository, you’d use this command:
git remote remove origin
Upon executing this command, the reference remotes
origin will no longer be associated with a remote repository. It’s worth noting this does not delete your remote repository or affect it in any way. All it means is that your local copy of a repository is no longer associated with a particular remote.
Alternatively, you can use the
git remote rm command.
git remote rm is simply a shorter version of the
git remote remove command.
You can verify if a remote has been removed by using the
git remove -v command. The -v flag shows the URLs to which each origin points. When you run this command, you’ll see something like this:
REMOTE https://github.com/OWNER/REPO.git (fetch) REMOTE https://github.com/OWNER/REPO.git (push)
Update a Remote
There’s no need to remove a remote if you just need to update its URL.
Let’s say that you want to change the URL of a particular remote. You can do so using the
git remote set-url command. Let’s say that we want to set the value of the
origin pointer to:
We could do so using this code:
git remote set-url origin https://github.com/career-karma-tutorials/web-tutorials
This will modify our
origin pointer to refer to the new URL we have specified. We can check if this change has been made by using the
git remove -v command like we did earlier.
git remove remote command allows you to remove a pointer to a remote repository from the Git command line. You can use the
git remote set-url command to change the value of a remote if you only need to amend its URL.
Now you’re ready to start removing and updating remotes like an expert developer!