0

how do I get a copy of a branch from a remote git server? I have tried the following options

git clone url
git clone url branchName  

it looks they get the master copy.

shebelaw
  • 3,992
  • 6
  • 35
  • 48
  • possible duplicate of [How to clone a single branch in git?](http://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git) – Simon Mar 18 '13 at 00:07

4 Answers4

5

You can use the the --branch or -b option on clone:

git clone -b <name> url

See man git clone for further details.

Femaref
  • 60,705
  • 7
  • 138
  • 176
1

when you clone you get ALL the branches and history.

good explanation here: git branch, fork, fetch, merge, rebase and clone, what are the differences?

use:

git-branch

once you clone the repository to see the branches in the repository.

Community
  • 1
  • 1
ERR0
  • 635
  • 4
  • 18
0
git clone url
git branch branchname
git checkout branchname
git pull origin branchname

this works for me afa i remember. there might be some better way though, i'm not a git pro.

Sinan
  • 11,443
  • 7
  • 37
  • 48
0

One way is to create a new repo and then fetch the branch alone:

git init .
git fetch <url> <branchname>:refs/remotes/origin/<branchname>
git checkout <branchname>

Caveat about the other answer on git clone -b

Git always clones the entire repository. What you have in your working directory is based on which branch you checkout. So if you want a particular branch, clone the repo and checkout the repo.

git clone -b is the shortcut for doing that.

Again, you are not getting a "copy" of your branch, but the whole repo with the required branch checked out.

manojlds
  • 290,304
  • 63
  • 469
  • 417