Skip to content

Instantly share code, notes, and snippets.

@mciverza
Last active May 26, 2017 08:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mciverza/2242fffec2d77b6f671663f4c7622c98 to your computer and use it in GitHub Desktop.
Save mciverza/2242fffec2d77b6f671663f4c7622c98 to your computer and use it in GitHub Desktop.
Git sparse checkout

sparse checkout in git

Downloading only part of a git repo, e.g one subfolder, is called a sparse checkout, or sparse clone

The steps to do a sparse checkout are as follows:

  • Start with an empty git repository: git init <repo_name>
  • Enter that directory: cd <repo_name>
  • Configure the remote repo address: git remote add -f origin <url_of_remote_repo>
  • Configure git to enable sparse: git config core.sparsecheckout true
  • Configure git, to define which files and folders should actually be downloaded by adding them, one per line, in .git/info/sparse-checkout:
    • echo some/dir/ >> .git/info/sparse-checkout
    • echo another/sub/tree >> .git/info/sparse-checkout
  • Pull from the the remote repo: git pull origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment