We clone a remote repository, check out a remote branch.
$ git clone https://github.com/limingth/meteor-master-classes.git
$ cd meteor-master-classes
$ git branch -r
origin/HEAD -> origin/master
origin/fanjinhui
origin/lichao
origin/limingth
origin/master
origin/sean
origin/tianchao
So the remote repository's name is "origin". First check the initial status of the repository:
$ git branch
* master
$ git remote show origin
* remote origin
Fetch URL: https://github.com/limingth/meteor-master-classes.git
Push URL: https://github.com/limingth/meteor-master-classes.git
HEAD branch: master
Remote branches:
fanjinhui tracked
lichao tracked
limingth tracked
master tracked
sean tracked
tianchao tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
Now checkout the remote branch:
$ git fetch
$ git checkout lichao
Check the status of the repository after checked out:
$ git br
* lichao <---
master
$ git remote show origin
* remote origin
Fetch URL: https://github.com/limingth/meteor-master-classes.git
Push URL: https://github.com/limingth/meteor-master-classes.git
HEAD branch: master
Remote branches:
fanjinhui tracked
lichao tracked
limingth tracked
master tracked
sean tracked
tianchao tracked
Local branches configured for 'git pull':
lichao merges with remote lichao <---
master merges with remote master
Local refs configured for 'git push':
lichao pushes to lichao (up to date) <---
master pushes to master (up to date)
You can see there are 2 kinds of relationship between local and remote branches: pull and push. Branch "lichao" and "origin/lichao" was linked bidirectional after checked out.
Some notes:
-
The name of the remote branch to be checked out is its full name except the "origin/" part, like "lichao" in
git checkout lichao
; -
git fetch
synchronize your local repository with remote side. So it's not necessary if you don't want sync with remote.
You can verify this by git branch -avv
.
Ref:
-
http://serverfault.com/questions/175052/how-to-tell-which-local-branch-is-tracking-which-remote-branch-in-git
-
http://stackoverflow.com/questions/1783405/checkout-remote-git-branch