Git is a distributed source code versioning system where repositories are used as central points and developers download and push changes to their locals. In an existing git project, the new remote repository can be added with the git remote add
command by specifying the remote repository URL, repository name, etc. In the tutorial, we examine how to add a new remote repository to the existing local git repository.
git remote add Command Syntax
The “git remote add” command has the following syntax.
git remote add REPO_NAME GIT_REPO
- The REPO_NAME is the repository name for the local git. Generally
origin
is used for naming. - GIT_REPO is the remote repository URL.
Add New Remote Repository
The “git remote add” is used to add a new remote repository in different ways. But the most popular way is specifying the remote git repository with the git protocol. In the following example, we add a new remote repository “git://wisetut.com/ismail/project.git“.
$ git remote add origin git://wisetut.com/ismail/project.git
If the remote git repository only supports HTTP protocol the following git repository URL can be used too.
$ git remote add origin http://wisetut.com/ismail/project.git
For HTTPS
$ git remote add origin https://wisetut.com/ismail/project.git
Verify New Remote Repository
After adding a new repository we can check and verify the newly added repository with the git remote
command. The “git remote” command lists the currently existing remote repositories and configurations.
$ git remote -v
> origin git://wisetut.com/ismail/project.git (fetch) > origin git://wisetut.com/ismail/project.git (push)