gitpractice.dev

home — Ch.10 · Clone only what you need

Exercise 6 of 6

Before you start

Why some repositories are slow

A clone downloads every version of every file ever committed. Large videos or design files make that huge, and they stay in history even after they are deleted.

Git LFS is an add-on that keeps such files outside the history and downloads only the versions you use. It is installed separately and not part of this practice terminal.

Taking less

A shallow clone has only the newest commits. A sparse checkout puts only some folders on disk. A partial clone (--filter=blob:none) has the whole history but downloads file contents when they are first needed.

git clone --depth <n> <url>
clone only the newest n commits
git clone --filter=blob:none <url>
partial clone
git sparse-checkout set <folder>
keep only that folder, and the top files
git sparse-checkout list
which folders are kept
git sparse-checkout disable
check everything out again
git fetch --unshallow
get the history a shallow clone left out
git log --oneline
see which commits you have
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path