0
0

create_bare_worktrees_repo_workspace.zsh 649 B

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