git remote
git remote
: manage remote repositories.
The git remote
command is used to manage connections to remote repositories. A remote in Git is a reference to a repository that exists somewhere else, typically on a remote server like GitHub, GitLab, or Bitbucket. Remotes allow you to collaborate with others by pushing your changes to and pulling changes from shared repositories.
The primary uses of the git remote
command are to list existing remotes, add new remote connections, and remove remotes that are no longer needed.
- Listing remotes: Simply typing
git remote
will list all the remote repositories connected to your local repository. - Adding remotes: To add a new remote, you use
git remote add
followed by a name for the remote and its URL. - Removing remotes: To remove a remote, you use
git remote remove
followed by the name of the remote you want to remove.
Examples
List all remotes in the repository:
git remote
List all remotes with their URLs (-v
is shorthand for --verbose
, meaning show extra details):
git remote -v
Add a new remote named 'upstream' pointing to a repository URL:
git remote add upstream https://github.com/original-author/project.git
Remove a remote named 'old-backup':
git remote remove old-backup
When you clone a repository, Git automatically creates a remote named origin
that points to the repository you cloned from. This is the default remote for most operations like git push
and git pull
.
Show detailed information about the 'origin' remote:
git remote show origin
Rename a remote from 'origin' to 'main-repo':
git remote rename origin main-repo