worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Feature: clone command

Open curtbushko opened this issue 9 months ago • 8 comments

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

curtbushko avatar Mar 04 '26 15:03 curtbushko

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.

worktrunk-bot avatar Mar 04 '26 15:03 worktrunk-bot

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

max-sixty avatar Mar 05 '26 00:03 max-sixty

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

curtbushko avatar Mar 05 '26 15:03 curtbushko

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?

max-sixty avatar Mar 05 '26 18:03 max-sixty

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.

curtbushko avatar Mar 05 '26 20:03 curtbushko

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!

max-sixty avatar Mar 05 '26 21:03 max-sixty

Sounds good! Thanks for building this and keep up the good fight!

curtbushko avatar Mar 05 '26 22:03 curtbushko

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

max-sixty avatar Mar 13 '26 23:03 max-sixty