worktree: generalize delete_git_dir() to reduce code duplication