How to Remove a Remote Git
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
A remote Git repository can be on a server, a Git cloud service (such as GitHub, GitLab, or Bitbucket), or on another developer’s machine. That enables many possible workflows for teams. One common workflow involves using a server repository as the “authorized” repository. Only reviewed, well-tested code is committed to it, often through a pull request issued from a developer’s repository.
What is a Git Remote?
A Git remote simply references a remote repository. Typically, there is at least one Git remote in a repository, named origin. Sometimes there are additional Git remotes in a repository, for example upstream. The term upstream generally refers to a repository from which another repository is derived, usually by cloning.
Create a remote in a local repository using the git remote add
command, for example:
git remote add origin https://github.com/user/repo.git
In this example, the first parameter, origin
, is the name of the remote. The second parameter, https://github.com/user/repo.git
, is the URL of the remote repository.
List the remotes in a repository using the git remote -v
command, where the -v
flag is short for --verbose
. This instructs the git remote
command to include the remote URL in the list. For example, use the git remote -v
command in a folder containing the TensorFlow repository:
cd repos/tensorflow/
git remote -v
This produces output such as:
origin https://github.com/tensorflow/tensorflow.git (fetch)
origin https://github.com/tensorflow/tensorflow.git (push)
How to Remove a Git Remote
There are three steps to remove a Git remote, with an optional verification step to confirm the removal.
First, open a terminal and change into the directory that holds your repository:
cd repos/tensorflow/
Second, list the remotes:
git remote -v
origin https://github.com/tensorflow/tensorflow.git (fetch) origin https://github.com/tensorflow/tensorflow.git (push)
Third, remove the remote/s:
git remote rm origin
In current versions of Git there are two forms of the command to remove a remote:
rm
andremove
. Therm
form goes back to the early versions of Git, while theremove
form was later added as an alias to help Windows users.Note Thegit remote rm
command simply removes the entries for the remote repository from the.git/config
file. It does not affect the actual remote repository. There is no need to worry about deleting the remote repository on the server as that cannot be done from a local Git command.There’s only one possible error message after issuing a
git remote rm
command:fatal: No such remote: '<remote-name>'.
A fourth, optional step is to confirm that step three worked by repeating step two:
git remote -v
This time, the removed remotes should not show up in the list. If all remotes were deleted, there is no output.
Alternatively, removing a remote and adding a new remote can be accomplished in one step using the git remote set-url
command, for example:
git remote set-url origin git@github.com:<github-username>/<repository-name>.git
To test this without modifying an established repository, create a new test repository on a Git hosting service (e.g. GitHub). Clone the new test repository to your local machine, then repeat the steps above in the cloned repository. A repository containing nothing but a small README.md suffices.
Conclusion
To summarize, create a remote in a local repository using the git remote add
command. List remotes using the git remote -v
command, and remove them using the git remote rm
command. This easy three- or four-step sequence for removing a remote is immensely helpful for anyone working with Git.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on