How to pull specific directory with git How to pull specific directory with git git git

How to pull specific directory with git


  1. cd into the top of your repo copy
  2. git fetch
  3. git checkout HEAD path/to/your/dir/or/file

    • Where "path/..." in (3) starts at the directory just below the repo root containing your ".../file"

    • NOTE that instead of "HEAD", the hash code of a specific commit may be used, and then you will get the revision (file) or revisions (dir) specific to that commit.


In an empty directory:

git initgit remote add [REMOTE_NAME] [GIT_URL]git fetch REMOTE_NAMEgit checkout REMOTE_NAME/BRANCH -- path/to/directory


After much looking for an answer, not finding, giving up, trying again and so on, I finally found a solution to this in another SO thread:

How to git-pull all but one folder

To copy-paste what's there:

git initgit remote add -f origin <url>git config core.sparsecheckout trueecho <dir1>/ >> .git/info/sparse-checkoutecho <dir2>/ >> .git/info/sparse-checkoutecho <dir3>/ >> .git/info/sparse-checkoutgit pull origin master

To do what OP wants (work on only one dir), just add that one dir to .git/info/sparse-checkout, when doing the steps above.

Many many thanks to @cforbish !