How to sparsely checkout only one single file from a git repository?

How do I checkout just one file from a git repo?

22 s
22

First clone the repo with the -n option, which suppresses the default checkout of all files, and the –depth 1 option, which means it only gets the most recent revision of each file

git clone -n git://path/to/the_repo.git --depth 1

Then check out just the file you want like so:

cd the_repo
git checkout HEAD name_of_file

Leave a Comment