Skip to content
Dave Anderson edited this page Jul 31, 2013 · 10 revisions

Remotes

git clone https://github.com/davious/Test.git
git remote -v
origin  https://github.com/davious/Test.git (fetch)
origin  https://github.com/davious/Test.git (push)

When you clone a repository, the copies of the repository branches are copied into refs\remotes\origin\. Remember, branches are just files whose name is the branchname and whose contents are a hash of the branch's current commit-tree.

Adding a remote

git remote add remotehandle https://github.com/davious/Test1.git

this adds a remote handle and its repository location information into the .git/config file.

This is useful when collaborating with a number of repositories, all cloned from the same repository.

Fetch

git fetch                 # uses the default remote repository, typically ``origin``

or

git fetch remotehandle

Fetch brings down all the changes made to the remote repository.

Pull

git pull        # uses the default remote repository and tracked branch

or

git pull remotehandle/remotebranch

git pull is a short-cut command.

git fetch                             # pulls down all repository changes into the remote branches
git merge remotehandle/remotebranch   # merges changes in the current (local) branch's from its default remotebranch

Setting Up Defaults

git checkout --track origin/abranch

Creates a local branch which pulls in changes from the remote branch of the same name. In the config file, an entry is created that looks like

[branch "abranch"]
        remote = origin
        merge = refs/heads/abranch

Push

git push                  # uses the default remote repository and current working branch

or

git push remotehandle alocalbranch 

Updates a remote repository branch with changes committed to your branch. If there are any changes to the remote branch you don't have, git will not push your changes. You must do a git pull first.

Clone this wiki locally