2

I need to fetch the files from just one specific branch. I have tried a couple of commands, but it ends up pulling the whole repo, instead of just the few files I need to pull to a directory from the specific branch.

git version 1.7.1

nicoX
  • 311
  • 6
  • 16
  • 1
    possible duplicate of [How to clone a single branch in git?](http://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git) – avi Oct 17 '14 at 10:30
  • `git clone git@bitbucket.org:name/name.git -b mv_LookbookAddition --single-branch` ends up with *error: unknown option `single-branch'* – nicoX Oct 17 '14 at 10:36

1 Answers1

7

If you get an error on:

git clone git@bitbucket.org:name/name.git -b mv_LookbookAddition --single-branch

It means you need to 1.7.10+ (June 2012), using, for Linux, a ppa or git-scm.com/download/mac for Mac.

But you will get the full history of the branch (if that branch has been created from master, you will get all the commits from master, up until the branch starts, plus the branch commits)

You can try and combine the --depth option to get only the last commits from the branch alone

git clone git@bitbucket.org:name/name.git -b yourBranch --single-branch --depth 10

That will your cloned repo a shallow repo, which is why you want a git 2.0+ (because you can create commits and push back, from your shallow repo).

See explainshell.com.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If I do it with an updated Git version it will clone the whole repo, instead of the branch I specified. – nicoX Oct 17 '14 at 10:52
  • @nicoX I confirm it only clones the selected branch. What OS and what version of Git are you using? – VonC Oct 17 '14 at 10:52
  • Latest tested with *git version 1.8.3.2* on my *Ubuntu 13.10*. My branch is on *Bitbucket*, it's not merged with the `master` branch. – nicoX Oct 17 '14 at 11:04
  • @nicoX Ok. Use the ppa I mention (like https://launchpad.net/~git-core/+archive/ubuntu/ppa) and upgrade to 2.1.1. Clone that BitBucket repo in a separate non-existing local folder. – VonC Oct 17 '14 at 11:05
  • Updated to *2.1.1*. It's still counting all my files when cloning, instead of the branch that only contains +-30 files: `Cloning into '/home/user/test_55'... remote: Counting objects: 19293, done. remote: Compressing objects: 100% (9630/9630), done. Receiving objects:` – nicoX Oct 17 '14 at 11:21
  • @nicoX that is a *remote* message, and it should compress and transmit only the files of your branch (with their *all* history, *all* their commits, so a bit more than ~30) – VonC Oct 17 '14 at 11:22
  • It still fetching the whole master branch and repo. – nicoX Oct 17 '14 at 16:42
  • @nicoX if your branch starts from master, this is working as expected. – VonC Oct 17 '14 at 16:45
  • I'm not sure I understand now. I just want to download the branch I specified, it's just small changes, which would take some seconds. This command is cloning my whole repo which is taking one hour to download. My brach is `mv_LookbookAddition` it fetches that one as well, seems to work, as it's not merged with master, but I don't want anything else other than my `mv_LookbookAddition` branch to be pulled. – nicoX Oct 17 '14 at 17:02
  • 1
    @nicoX cloning a single branch means getting all the commits accessible from that branch, all the way to the first one: you can clone only one branch, but you will get its full history. Again, everything is working as expected. – VonC Oct 17 '14 at 17:07
  • 1
    @nicoX You can try (as I explain the edited answer) to add `--depth n`, in order to get only the last `n` commits: that would be closer to what you are looking from. – VonC Oct 17 '14 at 18:22