Skip to content

Instantly share code, notes, and snippets.

@hu8813
Forked from dinhvle/git-clone-sub.md
Created March 1, 2024 14:20
Show Gist options
  • Save hu8813/b296be383773c9f12845a7fc81abeac9 to your computer and use it in GitHub Desktop.
Save hu8813/b296be383773c9f12845a7fc81abeac9 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