Skip to content

Instantly share code, notes, and snippets.

@dinhvle
Created April 19, 2021 22:01
Show Gist options
  • Save dinhvle/d085848c09ebd7d3a4a52de9f026c0d3 to your computer and use it in GitHub Desktop.
Save dinhvle/d085848c09ebd7d3a4a52de9f026c0d3 to your computer and use it in GitHub Desktop.
Clone Only a Subdirectory with Git

Source: https://en.terminalroot.com.br/how-to-clone-only-a-subdirectory-with-git-or-svn/ Alt: https://bytenota.com/git-how-to-clone-a-specific-directory-from-a-git-repository/

# Create a directory, so Git doesn't get messy, and enter it
mkdir my-dir && cd my-dir

# Start a Git repository
git init

# Track repository, do not enter subdirectory
git remote add -f origin https://github.com/terroo/fonts/

# Enable the tree check feature
git config core.sparseCheckout true

# Create a file in the path: .git/info/sparse-checkout
# That is inside the hidden .git directory that was created
# by running the command: git init
# And inside it enter the name of the sub directory you only want to clone
echo 'files' >> .git/info/sparse-checkout

## Download with pull, not clone
git pull origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment