Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
# Check if we're in a worktree of a bare repo and capture absolute path
common_dir=$(git rev-parse --git-common-dir 2>/dev/null) || {
echo "ERROR: Failed to get git-common-dir: are you in a git repo?"
exit 1
}
if [ -n "$common_dir" ] && grep -q "bare = true" "$common_dir/config" 2>/dev/null; then
echo "BARE REPO DETECTED"
echo "BARE_ROOT: $common_dir"
else
echo "NON-BARE REPO DETECTED"
fi
If failed to get git-common-dir:
If bare repo detected:
BARE_ROOT for later useIf non-bare repo detected: