2

I have a repo called as 'color-palette ( https://github.com/3gwebtrain/color-palette.git) and it has other branches too.

I would like to clone one of the branch called same-color to my local system. But not working.

the command i used is :

git checkout -b https://github.com/3gwebtrain/color-palette.git origin/same-color

But this is not working. getting error as :

fatal: Not a git repository (or any of the parent directories): .git

what is wrong here?

dimid
  • 7,285
  • 1
  • 46
  • 85
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • 1
    `git clone https://github.com/3gwebtrain/color-palette.git && cd color-palette && git checkout same-color`, as any tutorial would tell you. – Biffen May 09 '16 at 13:33
  • http://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git – dimid May 09 '16 at 14:08

2 Answers2

4

You don't clone just 1 branch of a git repo, you clone the repo, and then checkout that branch.

First clone it

git clone https://github.com/3gwebtrain/color-palette.git

then, in that folder, checkout the branch

git checkout same-color

You don't want to use -b option during checkout, because that creates a new branch

Tim
  • 41,901
  • 18
  • 127
  • 145
  • I didn't get the result. here is my try : ` C:\Tutorials\try\testing>git clone https://github.com/3gwebtrain/color-palette.git Cloning into 'color-palette'... remote: Counting objects: 256, done. remote: Compressing objects: 100% (24/24), done. Receiving objects: 87% (223/256), 332.01 KiB | 137.00 KiB/s 28R Receiving objects: 100% (256/256), 431.63 KiB | 137.00 KiB/s, done. Resolving deltas: 100% (210/210), done. Checking connectivity... done. C:\Tutorials\try\testing>git checkout same-color fatal: Not a git repository (or any of the parent directories): .git ` – 3gwebtrain May 09 '16 at 13:39
  • 1
    You want to do `cd color-pallete` after clone and before checkout, so that the checkout is done in the directory where the git lives – Tim May 09 '16 at 13:40
  • You can now clone just a single branch's history via `git clone --single-branch`. It is probably not generally recommended, but it is allowed. – Mort May 09 '16 at 14:18
  • @Mort that's neat. Do you know since which version exactly? – Tim May 09 '16 at 14:53
  • @TimCastelijns A quick web search reveals 1.7.10 https://raw.githubusercontent.com/gitster/git/master/Documentation/RelNotes/1.7.10.txt – Mort May 09 '16 at 15:23
2

I have done with below single git command:

git clone https://github.com/3gwebtrain/color-palette.git -b same-color --single-branch
pRaNaY
  • 24,642
  • 24
  • 96
  • 146
  • do you have any idea to specific commit id to merge with other branch? – 3gwebtrain May 09 '16 at 13:51
  • You need to see [cherrypick](https://git-scm.com/docs/git-cherry-pick). You can also see [What does cherry-picking a commit with git mean?](http://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean) and [Git - Cherry pick a single commit for pull request](http://stackoverflow.com/questions/25955822/git-cherry-pick-a-single-commit-for-pull-request) . Its helps you. – pRaNaY May 10 '16 at 14:23