Checkout sub directories in git (sparse checkouts)

SVN externals is a really nice feature I used a lot. Switching to git I was really missing it. Of course there is git-submodule but it’s not the same. Now, with version 1.7 git supports so called sparse checkouts which allow you to only include specific sub directories of a repository in your project. You still need to clone the whole repository, but afterwards you can tell git to only show the specified sub directories.

Here is how it works:

  1. clone the other repository (in my case, for a Rails app, I did it in vendor/plugins/)
    git clone <repository_url> <directory>
  2. cd to <directory>
    cd <directory>
  3. enable sparsecheckout
    git config core.sparsecheckout true
  4. add directories you want to have in your checkout to .git/info/sparse-checkout, e.g.
    echo app/models/ > .git/info/sparse-checkout
    echo lib/ >> .git/info/sparse-checkout
  5. run read-tree
    git read-tree -m -u HEAD

ls now shows

app lib

Forgot a directory you wanted to include? Just repeat step 4 and 5.


  1. Awesome! Exactly what I was looking for…

  2. What if I want to checkout all but one? Is there an exclusion command?

    And, what about files? Do they have to be added to .git/info/sparse-checkout as well?


  3. These command should be run on server side on client also let me how can take single file git pull and git push command.

  4. Is it possible to configure multiple sparse ?

    For example I want a sparse checkout for each jenkins job I have. So I will like Job A to only get /FolderA when executed and Job B only to get /FolderB when executed. As the config looks global I’m confused :S


  5. My friend smiled and told me to look into this blog post and i noticed it relatively impressive. I will bookmark it for a future needed along with i might tell a friends to examine this blog post. Thanks plenty for writing.

  6. Thanks for that explanation. I was pointed here from a stackoverflow answer that explains you can do this to submodules too.

    The only thing I can’t figure out is how to commit this to the parent repository so that everyone checking out the parent repository will get the sparse checkout for submodules.

    Any idea?

  7. I like the helpful information you provide in your articles.

    I’ll bookmark your weblog and check again here frequently.
    I’m quite certain I will learn lots of new stuff right here!

    Good luck for the next!

  8. Can I simply say what a relief to discover somebody that actually knows what they are talking about over
    the internet. You certainly know how to bring an issue to light and make it important.

    More people should read this and understand this side of your story.
    I can’t believe you are not more popular because you
    definitely have the gift.

  9. 按照你说的方法,实现了,想要的功能。可是,我做好了的“本地库”推送 “”,或者在本地clone一份刚刚做好的“本地库”的时候,新的“版本库”有还原到第二步了。有什么方法使得“新clone版本库”的和按你的方法整理过的“版本库”一样的啊?

  10. Useful info. Lucky me I found your web site unintentionally,
    and I’m surprised why this twist of fate didn’t happened in
    advance! I bookmarked it.

  11. Everything is very open with a very clear explanation of the challenges.
    It was really informative. Your website is useful. Thank you for sharing!

  12. Every weekend i used to pay a visit this website,
    for the reason that i want enjoyment, since this this
    web page conations really fastidious funny material too.

  13. The passenger provides points on your licence
    another pair of eyes on the road, and the matter was adjourned until
    next week. But the storm was still strong enough to kill three
    people, including a lifting of the ban as she claimed she would be if she had her own
    car to drive his car. A man who was on the other hand, 68 percent of those surveyed last year, achieving seventh

  14. Just want to say your article is as amazing.
    The clearness in your post is simply excellent and i
    can assume you are an expert on this subject.
    Fine with your permission let me to grab your feed to
    keep updated with forthcoming post. Thanks a million and
    please keep up the rewarding work.

  15. Hi, I read your new stuff regularly. Your humoristic style is witty, keep
    doing what you’re doing!

  16. Does your website have a contact page? I’m having a tough time locating it but, I’d like to shoot you an email. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it expand over time.

  17. Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it. dbdddecbdgge

  18. Hola! I’ve been reading your weblog for a long time now
    and finally got the courage to go ahead and give you a shout out from Atascocita Texas!
    Just wanted to tell you keep up the great

  19. Just desire to say your article is as astounding.
    The clarity for your put up is simply nice and i can assume you’re an expert in this subject.

    Fine together with your permission let me to seize your RSS feed to
    stay up to date with imminent post. Thanks a million and please carry on the enjoyable work.

  20. hi . i want to clone nly 1 perticular file from thre repository, can u tell me the cmmand for that…

  21. I’m not sure exactly why but this site is loading incredibly
    slow for me. Is anyone else having this issue or is it a
    problem on my end? I’ll check back later and see if the problem
    still exists.

  22. Dr. Patel Dentis

    Checkout sub directories in git (sparse checkouts) « General «

  23. They’re also a very good comply with on Twitter for the latest on SEARCH ENGINE OPTIMISATION and Search
    advertising (at @SEOmoz ).

  24. With havin so much content do you ever run into any problems of plagorism or copyright infringement?

    My website has a lot of completely unique content I’ve either written myself or outsourced but it seems
    a lot of it is popping it up all over the web without my
    permission. Do you know any methods to help stop content from being ripped off?
    I’d genuinely appreciate it.

  25. A site that isn’t indexed much by Google or doesn’t turn up until page 1,993,990 on a Google search for its kind is WORTHLESS to you.
    Penguin algorithm that got rolled out in April,
    2012 almost shook SEO industry. ‘ Voicemail Transcription – Keeps a
    log and reads what the voicemail says.

  26. Hi! Do you use Twitter? I’d like to follow you if that would be ok. I’m undoubtedly enjoying your blog and look forward to new posts.

  27. I’ll immediately seize ones rss feed once i won’t be able to locating a person’s e-mail ongoing web page link and also e-newsletter assistance. Do you may have almost any? Be sure to let us understand to ensure that I might sign up Fargo Restaurants. Thanks a lot.

  28. Failure to keep paying the mortgage may result in your home being repossessed.
    Navigation menus are characteristically generated automatically based on the content
    uploaded in the database. If the answer is yes, they will be less likely to be able to service more.

  29. Very soon this web site will be famous among all blogging people, due to it’s nice posts

  30. It’s become simpler to send money today than in the past. Sending money
    on the internet is an easy and quick procedure that often results in money arriving promptly as
    well. Lots of people prefer to know how to
    transfer money to Italy.

  31. Actually no matter if someone doesn’t understand afterward its up to other visitors that they will help, so here it occurs.|

  32. I savor, lead to I discovered just what I was looking for.

    You have ended my 4 day long hunt! God Bless you man. Have a
    great day. Bye

  33. Very soonn thus web site will bee famous among all blogging viewers, due to it’s nide articles or reviews

  34. Espresso unsightly stains are extremely very easy to get rid of. You need to use a dried out hand towel to soak up because the spot as you possibly can and use a humid hand towel to wash the remainder. Put a little volume of vinegar for the discolor, wait around a couple of minutes along with take in the particular vinegar as well as the rest of the caffeine which has a damp hand towel.

  35. For anyone who is on the lookout for adult porn social signals, then think about obtaining our adult social signal package.
    It’s the best way to get larger search positions on the internet
    when yoou aare a sex sites web site website owner.

  36. Progress toward elimination of Haemophilus influenzae type
    b invasive disease among infants and children – United States, 1998-2000.

  37. 050 m g/l at 79 hours post injection, of radioactivity at subsequent
    time points performed not look like clenbuterol.

  38. So my biggest worry is what type of world are we leaving to the children and grandchildren and theirs in turn.

  39. But his deep-seated fears, his inborn weaknesses – those things we share intimately.

  40. In fact, the Amero is already being bandied about as a
    replacement for the dollar-dollar-peso format now in place.

  41. junto de websites, lists a telephone number that is disconnected.

  42. Grow in natural approach and result a lot more effective.

  43. It is not better to select high-heeled shoe, if you are an obese.

    They are going to almost any extent to look good
    and attractive. Moccasin UGG slippers are quite popular among
    the men.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>