Please see also the other answer which many people prefer.
You may also want to make sure you understand the difference, unlike the majority of angry commenters and downvoters. And the difference is: by invoking git clone -b branch url
you're fetching all the branches and checking out one. That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your frontpage, you may end up cloning 5GB of data.
Again, that is not to say git clone -b
is not the way to accomplish that, it's just that it's not always what you want to accomplish, when you're asking about cloning a specific branch.
The answer I would write today, with today's git in mind would be
git clone --single-branch -b branch host:/dir.git
at the time of writing the original answer below, git had no --single-branch
option, but let's preserve it for full satisfaction of angry bees.
The answer so badly disliked by copypasters was this:
git init
git remote add -t refspec remotename host:/dir.git
git fetch