Skip to content
Dave Anderson edited this page Aug 11, 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

Pull --Rebase

git pull --rebase is a short-cut command.

git fetch                             # pulls down all repository changes into the remote branches
git rebase remotehandle/remotebranch  # rebases changes in the current (local) branch's off of its default remotebranch

Setting Up Defaults

git checkout -b feature origin

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

[branch "feature"]
        remote = origin
        merge = refs/heads/master

tracking an origin branch

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

There is many ways of actually doing this; they all just edit the config file.

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.

Pushing and Rebasing

Do not track a public branch, rebase it locally, and push it to the public branch. Other people working on that branch will be hosed on their next pull.

Clone this wiki locally