Note: Better description here.
Our current project is held in a git repository. It is set up for anonymous (cvs/subversion style) push/pull operation using an ssh keypair so that we don’t need to enter password.
Recently we have been experimenting with branches. Two main branches exists: origin (which represent the serverside copy) and master (which represents the clientside copy). In git, ordinary branches exists only on the clientside and are not transferred when pushing. The solution is to use remote branches. A few commands for listing available branches:
(A) git branch
(B) git branch -r
(C) git branch -a
They list local branches (A), remote branches (B) and both local and remote branches (C). An asterisk is used to mark the current branch.
One does not work directly on a remote branch. Instead you create a corresponing local branch which tracks the remote branch. The syntax is
git checkout --track -b LOCAL_BRANCH_NAME origin/REMOTE_BRANCH_NAME
where LOCAL_BRANCH_NAME is the name of the local tracking branch and REMOTE_BRANCH_NAME is the name of the the remote branch.
Pulling works as expected, but pushing to a remote branch is a bit more complicated than one might expect. The syntax is
git push origin LOCAL_BRANCH_NAME:REMOTE_BRANCH_NAME
I’m sure there exists some fancy way to store this information so that a ‘git push‘ would do as expected, but at the moment we will cope.
Full description at this page.
Man pages of interest:
git branch
git push
git checkout
References:
Checking out a remote branch
Pushing to a remote branch (see examples)