Feature: clone command
Good day!
One of the gotchas of using work trees is that git is not too prescriptive of the correct way to create work trees. For example, you can use .git (which can cause problems) and .bare. This confuses people and probably results in extra bug reports on your end.
My request is for a wt clone https://github.com/max-sixty/worktrunk.git command that results in:
.
├── .bare
├── .git
└── main
main being whatever the default branch is
Thanks for the suggestion! This is a feature request rather than a bug, so I'll leave it for a maintainer to evaluate and prioritize.
would you mind explaining the layout a bit more? it sounds like it's a layout that has worked well for you, so I'm keen to understand it.
though for transparency: it's unlikely we encode a specific way of cloning; I haven't seen one approach that so dominates others
https://github.com/max-sixty/worktrunk/issues/1214 would help on an individual basis, although possibly your suggestion is more normative than that
I can definitely explain more. I think the problem is that I haven't seen one approach that so dominates others and thus folks just do whatever and you get bug reports for bare clone problems that are not worktrunks fault...
A tiny background, I've been using work trees for a few years now and I've broken many repos by not using bare repos correctly/consistently. The articles below explain the pattern I follow (1) and the complications of using that pattern (2). I kept on breaking it so much that I wrote my own CLI to do this for me. Feel free to use the clone code as a reference. I'd like to selfishly replace my tool with yours for day to day.
How to use git worktree and in a clean way Workarounds to git worktree using bare repository and cannot fetch remote branches
The overall logic is pretty simple:
#!/usr/bin/env bash
set -e
# Examples of call:
# git-clone-bare-for-worktrees [email protected]:name/repo.git
# => Clones to a /repo directory
#
# git-clone-bare-for-worktrees [email protected]:name/repo.git my-repo
# => Clones to a /my-repo directory
url=$1
basename=${url##*/}
name=${2:-${basename%.*}}
mkdir $name
cd "$name"
# Moves all the administrative git files (a.k.a $GIT_DIR) under .bare directory.
#
# Plan is to create worktrees as siblings of this directory.
# Example targeted structure:
# .bare
# main
# new-awesome-feature
# hotfix-bug-12
# ...
git clone --bare "$url" .bare
echo "gitdir: ./.bare" >.git
# Explicitly sets the remote origin fetch so we can fetch remote branches
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# Gets all branches from origin
#git fetch origin
git worktree add main
and you get bug reports for bare clone problems that are not worktrunks fault...
just so I ground my understanding — are you referring to concrete bug reports? or just in the abstract?
Abstract. I just assume it would be a thing based on the lack of standards for the worktree layout from git.
Note: I can survive without clone and maybe the alias feature would be enough. Appreciate your time and thought that went into this.
my sense is that this is a good approach, and Worktrunk should support those who use it; but we want to be secular over lots of approaches, and very selective over what we mandate or even default to
I hope that's reasonable! I'll try and work on the alias feature and then happy to hear how that's going when it's rolled out. And I'd encourage proselytizing the approach so that it does become standard!
Sounds good! Thanks for building this and keep up the good fight!
The alias feature has shipped since this was closed (docs). It could cover some of the use cases here — for example, a post-setup alias that configures fetch refs or fixes HEAD.
One limitation: aliases run via wt step, so they need an existing repo. A clone operation that creates a repo from scratch would still need to be a standalone script. But the alias feature could complement that — e.g., a setup alias that runs the fixup steps after the initial clone.
This was written by Claude Code on behalf of @max-sixty