~vijaykumar

[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]

Notes on Git Remotes

Mon, 19 Nov 2012

A remote is a convenient way of referring to a remote repository, so that the user doesn’t have to type the entire URL again and again.

Moreover since git is a distributed, the user might want to refer to serveral remote repositories, to obtain changes from. Remotes let the user to conveniently name these different remote repositories.

When a project is cloned, a remote called origin is automatically created. The remote refers to the repository from which the project was cloned.

To view the currently available remotes, do

git remote

To vew details about a remote

git remote show <remote-name>

Remote Branches

The branches available in the remote repository are visible in the local repository and are called remote branches.

The remote branches are read-only, in the local repository. These are available so that branching operations like branching, merging, rebasing, etc. can be performed.

To view the list of remote branches

git branch -r

The remote branches are generally referred to as <remote-name>/<remote-branch-name>.

Getting Updates from a Remote

The changes from a remote repository can be obtained using the following command

git fetch <remote-name>

When the changes are fetched the corresponding remote branches in the local repository gets updated. Changes from the remote branches can then be merged into the local branches using

git merge <remote-branch>

Adding more Remotes

When the user wants to receive/send changes to another repository, other than from the repository that the user cloned from, a new remote has to be added.

git remote add <name> <url>

The changes can then be fetched from the remote repository using

git fetch <remote-name>

Sending Changes to a Remote

When the user wants to send changes to a remote the push command can be used.

git push <remote> <local-branch>:<remote-branch>

Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: foss, git

blog comments powered by Disqus

Powered by Python | Made with PyBlosxom | Valid XHTML 1.1 | Best Viewed With Any Browser | Icon Credits | CC-BY-SA