Checkout Specific Directory Within Git Repo

I believe that the first test of a truly great man is his humility. Really great men have a curious feeling that the greatness is not in them but through them. And they see something divine in every other man and are endlessly, incredibly merciful.

— John Ruskin.

One day I was working on a driver port to macOS (Apple Macintosh OS) and the only opensource code for it can be found on Linux kernel.

Heck! The Linux kernel repository is around 2GB including all history and I only needed a specific directory inside the repository. After searching the whole internet I found an answer1.

Here are the steps to clone a specific directory from a git repository:

  1. First and foremost you need to create a local blank repository on your workstation. git init <repo-url>
  2. Inside the created bare repository, map the remote URL of the remote repository you want to clone. cd <repo-name> git remote add origin <remote-repo-url>
  3. Then, setup the git config and specify that you’ll be doing a sparse checkout. git config core.sparsecheckout true
  4. Create and add all the directories you want to checkout in the sparse-checkout file that can be found in .git/info/sparse-checkout. echo "<needed-directory>/*" >> .git/info/sparse-checkout
  5. When all the above steps is done, finally pull the repository objects. git pull --depth=1 origin master

So guys if you have any questions? hit me up on my social media accounts. That’s all there is that is needed. Now its already cloned and can now be worked on.

❌ Originally posted on August 5, 2019.

  1. ↩︎




  • Let’s Explore!

    It’s 04:03am Tuesday, and I’m starting this blog. There are a lot of things currently bothering my mind, and sometimes I’m thinking of what the future will look like. Waiting till 10:00 to get onto my work and start doing some stuff. Let’s find some beautiful place and get lost. – Me I’ve been a… Read More

  • Installing MySQL2 Ruby Gem in macOS Mojave

    Installing MySQL2 gem became a common problem for people who uses macOS to develop Ruby1 based apps that utilized MySQL2 data store. I’ve personally encountered this problem myself back in the days and still encountering this on brand new setup macOS workstation. In this article, we will go through the steps I did to resolved… Read More

  • Changing Xserver Default Applications Using XDG Tools

    XDG ( which stands for X Desktop Group is a group which develop the X11 and xdg utilities which currently runs as barebones of linux desktop. So how do we change the defaults when opening a file on XServer? Be free, and live life fully. — Caroline Shaw. So how do we configure XDG? Tools… Read More