David David - 2 months ago 16x
Git Question

Git fetch remote branch

My colleague and I are working on the same repository we've branched it into two branches each technically for different projects, but they have similarities so we'll sometimes want to commit back to the *master from the branch.

However, I have the branch, how can my colleague pull that branch specifically. A git clone of the repo does not seem to create the branches locally for him, though I can see them live on unfuddle after a push my end.

Any help would be greatly appreciated.

*Edit, also when I originally made the branch I did -b checkout. Not sure if that makes much difference?

*Edit 2

iMac:test_solar dave$ git branch -r
origin/HEAD -> origin/master

git fetch origin discover
git checkout discover

This is the commands I ran. But definitely no workey. I want to be able to check out that branch and then push and commit back just that branches changes from various collaborators or workstations.


You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated.

For most versions of git:

git checkout --track origin/daves_branch

--track is shorthand for git checkout -b [branch] [remotename]/[branch] where [remotename] is origin in this case and [branch] is twice the same, daves_branch in this case.

For git you needed this:

git checkout --track -b daves_branch origin/daves_branch

For git and higher this is enough (might have started earlier but this is the earliest confirmation I could find quickly):

git checkout daves_branch

full details here: http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches