1

I am new to using Git and now i am trying on my repositories.
I have a repository where I have put many folders in it.

Now in my new project, I want to grab specific folders from that repository.

Can I do that in Git? I have uploaded my repo to BitBucket.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Mirage
  • 30,868
  • 62
  • 166
  • 261
  • possible duplicate of [Is there any way to clone a git repository's sub-directory only?](http://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only) – Pfitz Dec 06 '12 at 06:43
  • Do you want to create a new repo containing only one of the subfolders while preserving all it's history? – the.malkolm Dec 06 '12 at 09:52

2 Answers2

2

If you really need only certain directories, you should declare them as submodule of your main git repo.
That way, those directories are in their own git repo, and you can clone them independently of the parent repo.

Otherwise, what you want is called sparsed checkout (as opposed to shallow clone, which clone part of the history of the all repo), and, as mentioned in "Partial clone with Git and Mercurial", wasn't possible with Git.
Git1.7.0 includes it with git read-tree (but you still need to clone the full repo).
See "Sparse checkout in Git 1.7.0?" for a script.

"clone parts of a github project" mentions other options.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

What you want is possible via sparse checkout, something I have explained in this answer: https://stackoverflow.com/a/13738858/758345.

But we warned: You are probably doing something wrong if you need this feature. You should probably gives us more information about your circumstances and what you are trying to achieve.

Community
  • 1
  • 1
Chronial
  • 66,706
  • 14
  • 93
  • 99