Shallow Clones

Shallow Clones and Fetching Specific Refs

A shallow clone fetches only the latest commits, which is all a CI build needs:

Shallow clones, deepening and fetching one branchShell
cd ..
git clone --depth 1 server/booknest.git shallow
rm -rf shallow
git clone -q --depth 1 file://$PWD/server/booknest.git shallow
cd shallow
git log --oneline
git fetch -q --deepen 2 && git log --oneline
git fetch origin dev-docs
cd ../booknest
Output
Cloning into 'shallow'...
warning: --depth is ignored in local clones; use file:// instead.
done.
a2508da Add an npm dev script that restarts on changes
a2508da Add an npm dev script that restarts on changes
dfab226 Document ?limit= and ?offset= in the README
10465b8 Add ?offset= to /api/books
From file:///home/dev/v5-ch2/server/booknest
 * branch            dev-docs   -> FETCH_HEAD

A plain-path clone ignores --depth; file:// forces the real protocol. The clone held one commit, --deepen 2 added two, and --unshallow would fetch the rest. --depth implies --single-branch, so dev-docs came only on request, into FETCH_HEAD; a refspec such as refs/heads/dev-docs:refs/remotes/origin/dev-docs would store it. Shallow history breaks git blame and merges across the cut; partial clone (Partial Clone) avoids that.