I have the following file structure
❯ tree -L 1
.
├── latex/
├── main/
├── simulator/
├── tscnn/
Each directory is a worktree. If I am on latex/, trying to to check out to another worktree yields
❯ git checkout main
fatal: 'main' is already checked out at '/path/to/main'
I want to quickly checkout to another worktree (that is, cd to another directory) without explicitly writing the path (e.g., in the previous example, /path/to/main)
How to do so?
There is no way to do that with Git but possible with a shell function that'd use additional Unix tools. This works for me:
Usage:
For bash completion add this to your
~/.bashrc:It relies on
_completion_loaderfrom packagebash-completion.