Git how to add a remote repository

This tutorial shows how to add a git repository to an already existing repository. This way modifications can be pushed to several remote repository.

Run the following command:


	git remote add NAME REMOTE_REPOSITORY

NAME is the name of remote repository in the locale repo. REMOTE_REPOSITORY is the connection to the remote repository

Here an example showing a repository being connected to 2 remote repositories named remote1 and remote2, the output will be:

$ git remote -v

$ git remote add remote1 file:///tmp/gitremote1/

$ git remote -v
remote1 file:///tmp/gitremote1/ (fetch)
remote1 file:///tmp/gitremote1/ (push)

$ git remote add remote2 file:///tmp/gitremote2/

$ git remote -v
remote1 file:///tmp/gitremote1/ (fetch)
remote1 file:///tmp/gitremote1/ (push)
remote2 file:///tmp/gitremote2/ (fetch)
remote2 file:///tmp/gitremote2/ (push)

The script first call the remote -v command and not branch is returned. Then it calls git remote add with the name and the address of the repository. Then the command git remote -v returns the new remote. Several remotes can be added to a git repository, so the scripts adds a second remote called remote2.

References:

Git

Recent Comments