How to Remove a Git Remote URL
Git remote is a hosted repository on a remote server shared by all team members to share their changes and work collaboratively. Generally, we have a single remote with different branches called origin
. We can manually add other remotes to our local git repository using git remote add REMOTE-ID REMOTE-URL
. The origin is set when we clone a git repository from the server. Sometimes we need to remove a remote URL from our local repository in cases like when the remote repository is moved to another host. We can remove a Git remote URL using git remote rm
and git remote remove
commands.
Remove a Git Remote URL Using git remote rm
We can use git remote -v
to view all the remotes of our local repository.
For example, we have set two remotes, origin
and upstream
.
git remote -v
Output:
origin git@gitlab.com:delftstack/programmingarticles.git (fetch)
origin git@gitlab.com:delftstack/programmingarticles.git (push)
upstream git@bitbucket.org:delftstack/test.git (fetch)
upstream git@bitbucket.org:delftstack/test.git (push)
We use the command git remote rm
followed by the remote name to remove a remote.
git remote rm upstream
It removes upstream
from the git remote list.
Now, if we view the remote list, we will notice that the upstream
is removed.
git remote -v
Output:
origin git@gitlab.com:delftstack/programmingarticles.git (fetch)
origin git@gitlab.com:delftstack/programmingarticles.git (push)
The git remote rm
command removes the entries about the specified remote repository from the .git/config
file.
We can also manually edit the .git/config
file to remove the git remote; however, it is not good practice.
When we try to remove a remote that is not present, we get an error saying fatal: No such remote: '<remote-name>'
.
git remote rm DelftStack
Output:
fatal: No such remote: DelftStack
In the example repo, there is only one remote named origin
. When we run git remote rm DelftStack
, we get an error because no DelftStack
remote is present.
Remove a Git Remote URL Using git remote remove
It is similar to the git remote rm
command and also works in a similar way.
We use the command git remote remove
followed by the remote name to remove a remote.
git remote remove upstream
This removes upstream
from the git remote list.
Suraj Joshi is a backend software engineer at Matrice.ai.
LinkedIn