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.
git 2.5 added the ability to have multiple working trees using git worktree. So this case, you'd use something like
git worktree add -b new-branch-name ../dir-name existing-branch
you can then change to dir-name and make your commits as usual. The commits will end up in your original repository (where you used worktree add
).
When you're done and everything you want is committed, you can delete the dir-name
folder and run git worktree prune
to clean up the orphaned worktree in your repo.