git remote
Check the status of and configure your remote repositories
If you are looking to check, or configure the connection to a remote Git repository from your local working copy you can use the git remote
command.
Adding a remote repository
To connect to a remote repository, run this command:
$ git remote add origin git@github.com:robertlyall/shop.git
This will add a remote, named origin that connects to the specified URL.
You can then run commands such as git pull
and git push
to update your working copy, or the remote respectively.
Removing a remote repository
If you have a remote already configured and you wish to remove the connection to it, simply type:
$ git remote rm origin
This will remove the connection to the remote named origin
. This does not effect anything on the remote itself and will prevent you from being able to push and pull.
View a list of currently configured remotes
If you want to check which remotes are already configured in your current repository, type:
$ git remote -v
origin git@github.com:robertlyall/shop.git (fetch)
origin git@github.com:robertlyall/shop.git (push)
The output as you can see above, shows the name of the repository, followed by the URL. If you have multiple remotes, they'll be displayed in an alphabetically ordered list in the same format.
Update an existing remote
You may need to update an existing remote, for example if you've migrated from one repository hosting provider to another. You can, of course, remove the old remote and add the new one, but a simpler way of doing it would be:
$ git remote set-url origin git@codebasehq.com:robertlyall/shop.git
This will simply overwrite the old URL for the remote named origin
.