Adding parts of a git repository as a submodule

  1. Add the repository as a submodule git submodule add <url> <path>
  2. Change into the created directory cd <path>
  3. Initialize a sparse-checkout git sparse-checkout init --cone
  4. Edit the created sparse-checkout file vim ~/.git/modules/<module-name>/info/sparse-checkout
  5. Whatever is added into the file will be kept. Can be negated by using !
!* # ignore all
<path-to>/<file-to-keep>
  1. git sparse-checkout reapply