Git Remove Remote: A Guide
The git remote remove command removes a remote URL from a repository. The syntax for this command is: git remote remove <remote-url>. You can only remove one remote at once.
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 do not affect 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 Git branch which is named origin . When you start a GitHub repository, for example, the instructions you’ll be asked to set up a remote named origin. You can change it, but origin is the default value.
With that said, you may need to change your remote at some point. That’s where the git remote remove command comes in handy.
Git Remove Remote: A Guide
The git remote remove command removes a remote from a local repository. You can use the shorter git remote rm command too. The syntax for this command is: git remote rm <remote-url>.
If you remove a remote accidentally, you will need to add it back manually using the git remote add command.
The git remote rm command does not remove a remote from a remote repository. This is because remote repositories do not keep track of your local remotes. A remote is local to your computer.
How to Remove Remote Origin in Git
Let’s remove a Git remote from a repository! To start, move into your repository directory. Then execute the following command:
git remote remove [name of the remote]
To delete the origin remote from your repository, use this command:
git remote remove origin
Upon executing this command, the reference remotes origin will no longer point to the 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.
"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"
Venus, Software Engineer at Rockbot
You can use the git remove -v command to verify if a remote has been removed. The -v flag shows the URLs to which each origin points. When you run this command, you’ll see something like this:
new https://github.com/career-karma-tutorials/web-tutorials.git (fetch) new https://github.com/career-karma-tutorials/web-tutorials.git (push)
We can see our “origin” remote has been successfully removed. But, our “new” origin remains.
Git Update Remote URL
There’s no need to remove a remote if you just need to update its URL. You can update a Git remote using the git remote set-url command.
Let’s say that you want to change the URL of a particular remote. We want to set the value of the origin pointer to:
We could do so by specifying the URL for the remote we want to use:
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 remote -v command like we did earlier.
To learn more about changing remotes, check out our How to Change a Git Remote guide .
The 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!
Do you want to learn more about Git? Check out our complete How to Learn Git guide for expert tips and guidance on top online learning resources.