Git
In this tutorial we will learn about Git remote to connect to repositories.
In Git, every developer working in the project gets their respective copy of the project repository. So, they have their own respective local development environment, branches and repository history.
Now, to connect with other developer's repository or to connect with the central repository we take help of the git remote
command.
To create a new remote connection we use the git remote add [name] [url]
command.
The name
is what we give to the connection. Its like a bookmark for the repository connection.
The url
is the url of the repository that we want to connect to.
Example:
$ git remote add origin git@github.com:yusufshakeel/git-project.git
In the above example I have created a new remote connection called origin
which is pointing at the central repository.
If we are cloning a central repository using the git clone
command then we automatically get a remote origin
connection pointing back to the repository.
In general, developers name the central repository of the project as origin.
The url of the remote repository that we want to connect to can be in HTTP or SSH protocol.
HTTP example:
https://github.com/yusufshakeel/git-project.git
SSH example:
git@github.com:yusufshakeel/git-project.git
The HTTP allows read-only access to the repository so, we can't push our commits to the repository. The SSH allows read-write access to the repository so, we can pull and push commits to the repository.
More on git pull
and git push
in the later part of this tutorial.
We use the git remote
command to list the connections.
$ git remote
origin
To list the connections with url we use the git remote -v
command.
$ git remote -v
origin git@github.com:yusufshakeel/git-project.git (fetch)
origin git@github.com:yusufshakeel/git-project.git (push)
To rename a connection we use the git remote rename [old_name] [new_name]
command.
$ git remote rename origin central-repo
Now, if we list the connections we will get the new name.
$ git remote -v
central-repo git@github.com:yusufshakeel/git-project.git (fetch)
central-repo git@github.com:yusufshakeel/git-project.git (push)
To delete a remote connection we use the git remote rm [name]
command.
$ git remote rm origin
ADVERTISEMENT