DEV Community

Cover image for Clone just the sub-folder in GIT ๐Ÿ”ฅ
Naman Gupta
Naman Gupta

Posted on โ€ข Edited on

17 5

Clone just the sub-folder in GIT ๐Ÿ”ฅ

Background

Hi there, Its Naman. I am sure that if you work with Git then you must have stumble across one of these situations at least once:

  • You need only one subfolder but don't want to clone the entire repo
  • You only need to play around the code and you don't care about the whole Git history.

For the first problem, there is no straightforward way/command available (Correct me if I am wrong). If the repo is small then you can clone the whole repo. Easy peasy, you won't think twice but if the repo is huge then you might think twice or maybe thrice. ๐Ÿ˜›

For the second problem, if you don't care about the code history then cloning history is overhead for you. We should skip if we can (A native way available but isn't friendly).

Solving problem ๐Ÿ›  :

I found this awesome package DeGit, created by Rich Harris (Creator of RollupJS and Svelte) quite a while back. This package is way easy to install and use. I use it frequently.

Note: Before moving forward make sure you have Node.js installed in your system. I recommend installing Node.js via nvm(Node Version Manager)

1- Install npm package ๐Ÿ“ฆ
Installing DeGit npm package

Use sudo npm i -g degit if your terminal shows permission error.

2- Cloning Sub-Folder โฌ‡๏ธ
Syntax: degit <repo-link/subfolder-name> <output-folder>
Alt Text
Here we are cloning components sub-folder and saving in our system with the same name.

3- Cloning whole repo without whole Git history

Syntax: degit <repo-link> <output-folder>

Alt Text

I โค๏ธ this. It's super fast. ๐Ÿš€

That's it for today. Feel free to provide any type of feedback. I highly appreciate that. Meanwhile, you can find me on Twitter @InsaneNaman.

Signing off. See you soon.

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
insanenaman profile image
Naman Gupta โ€ข

Thanks for pointing out. Yes it's a way and author of this package has also addressed here - github.com/Rich-Harris/degit#wait-...

nextjs tutorial video

Youtube Tutorial Series ๐Ÿ“บ

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series ๐Ÿ‘€

Watch the Youtube series

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay