Tracking remote branches after a `--single-branch` checkout
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.
Recent posts:
- Support PCRE2 or PCRE in `build-nginx`
- TIL: How to check and reset a directory tree of permissions with `chmod` and `namei`
- TIL: How to specify a host or hosts for an ansible-playbook without an inventory file
- Automating Jekyll card generation with ruby's Ferrum gem
- Use a basic Gmail account to "Send mail as" with a domain that uses Cloudflare email routing