#!/usr/bin/env zsh set -e repo_url=$1 target_dir=$2 [[ -z $repo_url ]] && read "repo_url?Repository URL: " [[ -z $target_dir ]] && read "target_dir?Target Directory: " target_dir=${~target_dir} mkdir -p "$target_dir"/{worktrees,scripts} cd "$target_dir" git clone --bare "$repo_url" .bare git --git-dir=.bare config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git --git-dir=.bare fetch origin git --git-dir=.bare remote set-head origin -a default_branch=$(git --git-dir=.bare symbolic-ref refs/remotes/origin/HEAD | sed 's|refs/remotes/origin/||') git --git-dir=.bare worktree add "worktrees/$default_branch" "$default_branch"