Open Source Projects
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.
git remote add [name] [url]
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.
$ git remote add origin email@example.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.
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
To list the connections with url we use the git remote -v command.
git remote -v
$ git remote -v
origin firstname.lastname@example.org:yusufshakeel/git-project.git (fetch)
origin email@example.com:yusufshakeel/git-project.git (push)
To rename a connection we use the git remote rename [old_name] [new_name] command.
git remote rename [old_name] [new_name]
$ git remote rename origin central-repo
Now, if we list the connections we will get the new name.
$ git remote -v
central-repo firstname.lastname@example.org:yusufshakeel/git-project.git (fetch)
central-repo email@example.com:yusufshakeel/git-project.git (push)
To delete a remote connection we use the git remote rm [name] command.
git remote rm [name]
$ git remote rm origin
Have fun learning :-)
Copyright © 2014 - 2018 DYclassroom. All rights reserved.
rendered in 0.0430 sec