work () { cd ~/my-base-repository.git git fetch if [ -n "$1" ] then if [ -d "$1" ] then cd "$1" elif git show-ref --verify --quiet "refs/heads/$1" then echo "Local branch '$1' already exists - creating worktree" git worktree add "$1" "$1" cd "$1" bun i elif git show-ref --verify --quiet "refs/remotes/origin/$1" then echo "Branch '$1' exists on remote - creating worktree tracking origin/$1" git worktree add --track -b "$1" "$1" "origin/$1" cd "$1" bun i else echo "Branch '$1' not found anywhere - creating new branch" git worktree add -b "$1" "$1" cd "$1" bun i fi else cd main fi }