So you had a super large git repo, and you only wanted to checkout a single branch (e.g. to potentially save some disk space). You probably have gone with:
git clone <url> --branch <branch> --single-branch
Now that you’re done with that branch, you want to checkout another branch for your next task. Not having “the entire history”, git will yell sth at you like this:
git checkout <another-branch> error: pathspec '<another-branch>' did not match any file(s) known to git
At this point, one of the things you can do is to “re-fetch” the new branch from remote. This worked for me:
git fetch origin <another-branch>:<another-branch> git checkout <another-branch>
I’m dead sure there are other ways to do it, just that this one works for me, and it’s a 2-liner, so it’s good enough. Sharing it for others like me & my future self.
NB: while unrelated to the main topic (as written in the title of this post), I’d love to include some resources I came across while researching. This is purely for the sake of giving credits: