Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you are trying to do is called a <strong>sparse checkout</strong>, and that feature was added in git 1.7.0 (Feb. 2012). The steps to do a sparse <em>clone</em> are as follows:</p> <pre><code>mkdir &lt;repo&gt; cd &lt;repo&gt; git init git remote add -f origin &lt;url&gt; </code></pre> <p>This creates an empty repository with your remote, and fetches all objects but doesn't check them out. Then do:</p> <pre><code>git config core.sparseCheckout true </code></pre> <p>Now you need to define which files/folders you want to actually check out. This is done by listing them in <code>.git/info/sparse-checkout</code>, eg:</p> <pre class="lang-bash prettyprint-override"><code>echo "some/dir/" &gt;&gt; .git/info/sparse-checkout echo "another/sub/tree" &gt;&gt; .git/info/sparse-checkout </code></pre> <p>Last but not least, update your empty repo with the state from the remote:</p> <pre><code>git pull origin master </code></pre> <p>You will now have files "checked out" for <code>some/dir</code> and <code>another/sub/tree</code> on your file system (with those paths still), and no other paths present.</p> <p>You might want to have a look at the <a href="http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/" rel="noreferrer">extended tutorial</a> and you should probably read the official <a href="http://schacon.github.com/git/git-read-tree.html#_sparse_checkout" rel="noreferrer">documentation for sparse checkout</a>.</p> <p>As a function:</p> <pre class="lang-bash prettyprint-override"><code>function git_sparse_clone() ( rurl="$1" localdir="$2" &amp;&amp; shift 2 mkdir -p "$localdir" cd "$localdir" git init git remote add -f origin "$rurl" git config core.sparseCheckout true # Loops over remaining args for i; do echo "$i" &gt;&gt; .git/info/sparse-checkout done git pull origin master ) </code></pre> <p>Usage:</p> <pre class="lang-bash prettyprint-override"><code>git_sparse_clone "http://github.com/tj/n" "./local/location" "/bin" </code></pre> <hr> <p>Note that this will still download the whole repository from the server – only the checkout is reduced in size. At the moment it is not possible to clone only a single directory. But if you don't need the history of the repository, you can at least save on bandwidth by creating a shallow clone. See <a href="https://stackoverflow.com/a/28039894/962603">udondan's answer</a> below for information on how to combine shallow <a href="https://git-scm.com/docs/git-clone" rel="noreferrer">clone</a> and sparse checkout.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload