2012年5月10日 星期四

[git] set up the local branch to track another remote branch


At first, I have a local code base "A", which I  git-clone it from a repo server. 
For some reasons, I would like to have another local code base "B", which contains the same things as "A".
I think it would be faster if I clones "A" to "B". 
so I do it as follow: 
git clone <path_of_A>/.git <path_of_B>

Then I got a code base B which tracks A insteads of tracking the repo sever. 
It means that, if I want to sync code base "B" with  the repo sever, I have to sync "A" with remote repo first,then sync "B" with "A". 
Since I only cares about changes in the repo server, I don't care about changes in "A". 
I removed the remote track of "A" and add a remote track of the repo server:
git remote add repo-server git@<IP_of_repo_server>:xxxx/xxx.git
git remote rm origin (origin is correspoing to "A")

Then I makes the local maser branch in "B" to track the repo server.
git branch --ser-upstream master remotes/repo-server/<the_remote_branch_name>