This is definitely one of those “because I always forget how to do it” posts.

I’ve got a large, multi-branch repository with a decade plus of commits. It’s much quicker to checkout just the branch I want, and with only the most recent commits (aka shallow clone):

# shallow clone just the wat branch:
git clone --depth 1 --single-branch --branch wat git@example.com:jaygooby/example.git

But then later, and because I’ve forgotten I’ve done the single-branch shallow clone, I can’t checkout other branches:

git checkout --track feature/weevils
fatal: 'feature/weevils' is not a commit and a branch 'weevils' cannot be created from it

Arg! So you need to:

git remote set-branches --add origin feature/weevils
git fetch origin
git checkout feature/weevils

And then you’re good to go.