Skip to content

Instantly share code, notes, and snippets.

@wdhowe
Created October 24, 2024 13:24
Show Gist options
  • Save wdhowe/99fa9b9c5557e59ba21eaa826af1c294 to your computer and use it in GitHub Desktop.
Save wdhowe/99fa9b9c5557e59ba21eaa826af1c294 to your computer and use it in GitHub Desktop.
Git: Checkout a single directory from a git repo

Git: Checkout a single directory from a git repo

Setup Directory

mkdir myrepo && cd myrepo
git init

Configure Repo

Setup

git remote add origin -f [email protected]:USERHERE/myrepo.git
git sparse-checkout init

# Repo top level dir to match on sparse checkout (can specify multiple, space separated)
git sparse-checkout set scripts

Verify

git sparse-checkout list

Pull

Pull just the matches from a certain branch due to the sparse-checkout list.

git pull origin main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment