Checkout Specific Files From Git


From Git 1.7 it is possible to checkout specific files from a repository. The feature in Git is called sparse checkout.

How To

Create a repository:
git init myRepo

where myRepo is the directory to create the new repository.

Go into the repository and tell it will use the sparse checkout feature:
cd myRepo
git config core.sparseCheckout true

Create a file called sparse-checkout in .git/info/:
vi .git/info/sparse-checkout

Add all the files you want to checkout using repository root as the starting point. For example:

Add the remote repository address. For example using one of my Github repositories:
git remote add -f origin

Change to your repository.

Set the branch:
git checkout master

The above should automatically pull the files down for only the specified files. Otherwise perform a git pull.


It’s not as easy to setup but once complete it makes it very easy to maintain.

Is it possible to do a sparse checkout without checking out the whole repository first?

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in SCM and tagged , , , . Bookmark the permalink.

Leave a Reply

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

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.