How to Remove a Git Remote

[ad_1]

This guide explains how to remove a Git remote.

Git remote is a pointer that refers to another copy of the repository that is usually hosted on a remote server.

Generally, when working with Git, you’ll have only one remote named origin and different branches for different features and environments. Origin is the name of the remote that automatically created when you clone a repository and points to the cloned repository.

However, when collaborating on a project with a group of people, you may find using multiple Git remotes very handy. The remote repository can be hosted on a Git hosting service such as GitHub, GitLab, and BitBucket or on your private Git server
.

If the remote repository is migrated to another host, or the contributor stopped making contributions, you may want to remove the remote URL from your repository.

Removing a Git Remote #

To remove a remote, navigate to the directory
your repository is stored at, and use the git remote rm (or git remote remove) command followed by the remote name:

git remote rm <remote-name>

For example, to remove remote named testing, you would type:

git remote rm testing

git remote rm removes all references to the remote repository. It does not remove the repository from the remote server.

To verify that the remote was successfully removed, use the git remote command to list the remote connections:

git remote -v  

The output will look something like this:

origin	https://github.com/user/repo_name.git (fetch)
origin	https://github.com/user/repo_name.git (push)

What the git remote rm command does is removing the entries about the remote repository from the .git/config file.

.git/config

...

[remote "testing"]
        url = [email protected]:user/repo_name.git
        fetch = +refs/heads/*:refs/remotes/testing/*

You can also remove the remote by editing the .git/config file using your text editor
. However, it is recommended to use the git remote rm command.

If the remote you are trying to remove doesn’t exist, Git will print an error message:

fatal: No such remote: '<remote-name>'

Perhaps you mistyped the name or the remote is already removed.

Conclusion #

Use the git remote rm <remote-name> command to remove a remote from a repository.

If you hit a problem or have feedback, leave a comment below.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.