Problem: I need somehow to checkout an existing branch of a project that is already cloned locally on my file system without being in that particular folder of this project.
You're quite welcome to use --git-dir
and --work-tree
to avoid cd'ing, but honestly, it's easier just to cd. To avoid having to cd back, you can do it in a subshell:
git clone foo foo-copy
(cd foo-copy && git checkout branch)
Of course, in this specific case, you don't actually need two commands:
git clone -b foo foo-copy