# 1. Create a new directory called “repo” in your home folder
mkdir ~/repo
# 2. Change into that directory
cd ~/repo
# 3. Print working directory to confirm you’re in /home/repo
pwd
# → /home/repo
# 4. Enable multiline editing in your shell (allows pasting or writing multi-line commands)
set -o multiline
# 5. Clone the remote repo without fetching blobs (files) and without checking out any branch yet
git clone --filter=blob:none --no-checkout https://<YOUR-GIT-REPO-URL>.git
# --filter=blob:none → omit file contents (only metadata)
# --no-checkout → do not populate working tree yet
# The result is an “empty” repo folder named <repo_name>
# 6. Enter the newly created repo directory
cd <repo_name>/
# 7. List files (should be empty since nothing is checked out)
ls -trlh
# total 0 → no files yet
# 8. Disable sparse-checkout (reset to full repo view)
git sparse-checkout disable
# 9. Initialize sparse-checkout in “full path” mode (no cone patterns)
git sparse-checkout init --no-cone
# 10. Define which paths to populate in working tree (only testfile.txt)
git sparse-checkout set --skip-checks testfile.txt
# 11. Verify your sparse-checkout configuration
cat .git/info/sparse-checkout
# → shows “testfile.txt”
# 12. Pull the target branch (Example branch: neovidya), fetching only the committed objects needed
git pull origin neovidya
# 13. List working-tree files—only testfile.txt should appear
ls
# → testfile.txt
# 14. Show which paths are currently in your sparse-checkout
git sparse-checkout list
# → testfile.txt
Explanation of the overall process:
- We create an isolated workspace (~/repo) and clone with --filter=blob:none + --no-checkout so Git doesn’t immediately download all file data.
- We then use “sparse-checkout” to tell Git exactly which paths we want (here, only testfile.txt), minimizing network I/O and local storage.
- Finally, we pull the branch and see only the specified file in our working directory.
Git’s partial-clone and sparse-checkout features to:
- Perform a “shallow” clone metadata-only (no file blobs downloaded)
- Initialize sparse-checkout to control exactly which paths get populated
- Fetch and check out only testfile.txt from the remote branch
- Minimize network I/O, disk usage, and local clone size
In short, you end up with just the one file you need (testfile.txt) instead of the entire repository.