{"id":5428,"date":"2019-07-03T11:27:21","date_gmt":"2019-07-03T16:27:21","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5428"},"modified":"2019-08-01T20:34:00","modified_gmt":"2019-08-02T01:34:00","slug":"sparse-checkout-with-git","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5428","title":{"rendered":"Sparse Checkout With Git"},"content":{"rendered":"<p>I&#8217;ve encountered a few repositories that are huge. Unwieldy huge, and stuffed with files that aren&#8217;t relevant to what <em>I<\/em> need. The straight-forward solution is to use multiple repositories &#8212; that&#8217;s what I do at work with my code samples. There&#8217;s a different repo for each language because the PHP developers really don&#8217;t care what the C# code looks like. The Java developers don&#8217;t need a copy of the Python code. But there are advantages to having a single repository that may preclude you from taking the simple solution. <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Git-Tools-Submodules\" target=\"_blank\" rel=\"noopener noreferrer\">Git sub-modules<\/a> are an interesting approach &#8212; combining multiple repositories into a single functional unit. But that&#8217;s a pretty big change to an existing repo. And, if you participate in open source projects, it may not be your decision anyway.<\/p>\n<p>There&#8217;s another option for selectively cloning when you&#8217;re working with a large repo &#8212; an option that doesn&#8217;t require any changes to the repository. An end user can perform a <em>sparse<\/em> checkout &#8212; essentially use a filter like .gitignore to select or deselect certain files\/folders from being pulled into the local working directory. The file is named sparse-checkout and is located in .git\\info &#8212; unlike a .gitignore file which indicates what <em>shouldn&#8217;t<\/em> get included, sparse-checking controls what <em>is<\/em> included (if you want an entire repo <em>except<\/em> one folder, use !path\/to\/folder\/**)<\/p>\n<p>The sparse-checkout file used to get <em>just<\/em> the core components of Scott&#8217;s OpenHAB helper libraries plus the OpenWeatherMap community scripts is:<\/p>\n<pre>.github\/**\r\nCore\/**\r\nCommunity\/OpenWeatherMap\/**<\/pre>\n<p>To use sparse checkout, set the core.sparseCheckout config value to true. You can add sparse checkout to a repo you&#8217;ve already cloned and use<\/p>\n<pre>git read-tree -mu HEAD<\/pre>\n<p>to &#8220;clean up&#8221; unwanted files. Or you can set up sparse checkout before you clone the repo<\/p>\n<pre>D:\\tmp&gt;<strong>mkdir ljrtest<\/strong>\r\n\r\nD:\\tmp&gt;<strong>cd ljrtest<\/strong>\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>git init\r\n<\/strong>Initialized empty Git repository in D:\/tmp\/ljrtest\/.git\/\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>git remote add origin https:\/\/github.com\/openhab-scripters\/openhab-helper-libraries<\/strong>\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>git config core.sparseCheckout true<\/strong>\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>copy ..\\sparse-checkout .git\\info\\<\/strong>\r\n1 file(s) copied.\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>git pull origin master<\/strong>\r\nremote: Enumerating objects: 3591, done.\r\nremote: Total 3591 (delta 0), reused 0 (delta 0), pack-reused 3591R ), 7.00 MiB | 6.95 MiB\/s\r\nReceiving objects: 100% (3591\/3591), 9.26 MiB | 7.22 MiB\/s, done.\r\nResolving deltas: 100% (1786\/1786), done.\r\nFrom https:\/\/github.com\/openhab-scripters\/openhab-helper-libraries\r\n* branch master -&gt; FETCH_HEAD\r\n* [new branch] master -&gt; origin\/master\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>dir<\/strong>\r\nVolume in drive D is DATA\r\nVolume Serial Number is D8E9-3B61\r\n\r\nDirectory of D:\\tmp\\ljrtest\r\n\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; .\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; ..\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; .github\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; Community\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; Core\r\n0 File(s) 0 bytes\r\n5 Dir(s) 386,515,042,304 bytes free\r\n\r\nD:\\tmp\\ljrtest&gt;<strong>dir .\\Community<\/strong>\r\nVolume in drive D is DATA\r\nVolume Serial Number is D8E9-3B61\r\n\r\nDirectory of D:\\tmp\\ljrtest\\Community\r\n\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; .\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; ..\r\n07\/03\/2019 09:07 AM &lt;DIR&gt; OpenWeatherMap\r\n0 File(s) 0 bytes\r\n3 Dir(s) 386,515,042,304 bytes free<\/pre>\n<p>Using sparse checkout, no one else has to do <em>anything<\/em>. Configure your client to get the files you want, and you&#8217;re set.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve encountered a few repositories that are huge. Unwieldy huge, and stuffed with files that aren&#8217;t relevant to what I need. The straight-forward solution is to use multiple repositories &#8212; that&#8217;s what I do at work with my code samples. There&#8217;s a different repo for each language because the PHP developers really don&#8217;t care what &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[233],"class_list":["post-5428","post","type-post","status-publish","format-standard","hentry","category-coding","tag-git"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5428"}],"version-history":[{"count":4,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5428\/revisions"}],"predecessor-version":[{"id":5492,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5428\/revisions\/5492"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}