Add --from flag to base worktrees on a non-default branch#1
Conversation
`tsk add` and `tsk create -a ...` now accept `--from <branch>` to base the new worktree's branch on `origin/<branch>` instead of the hardcoded `origin/main`. Default is unchanged, so existing usage is untouched. This is the multi-repo equivalent of `git checkout -b B` while sitting on branch A — useful when a task stacks on top of a feature branch that has not been merged to main yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lists three concrete scenarios where basing worktrees on a non-default branch is the right call: stacking on an unreleased feature branch, hotfixes against a release branch, and long-lived integration branches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Thanks for the PR! Totally agree this use case needs addressing. A few suggestions:
- Instead of
--from, I would call the flag--base - Instead of just the branch name (e.g.
--base dev) I would expect the whole remote-tracking branch (e.g.--base origin/dev) to avoid misleading into thinking the new base branch is local. - On top of that, I think this is the perfect opportunity to avoid hard-coding
origin/mainas the default base branch. Bothoriginandmaincould potentially be called differently. Ideally, tsk should use the name of the first remote configured (let's assume that's the default if there are multiple ones) and the default branch of that remote. (e.g. if the remote is calledupstreamand the default branch is calledmaster, this should automatically useupstream/masterinstead oforigin/mainas the base branch by default)
Addresses PR #1 review feedback: - Flag renamed from --from to --base. - --base now takes a full remote-tracking ref (e.g. origin/main); bare branch names are rejected so it's unambiguous whether a local ref or a remote-tracking one is meant. - The default base (when --base is not given) is no longer hardcoded to origin/main. It is resolved per repo as the first remote's default HEAD: cheap path via refs/remotes/<r>/HEAD, with an ls-remote --symref fallback for repos whose cache isn't set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates tsk add / tsk create -a … to allow choosing the remote-tracking branch that new worktree branches are based on, instead of implicitly basing everything on origin/main. It also adds logic to detect a repo’s default remote HEAD branch when no explicit base is provided.
Changes:
- Add
--base <remote>/<branch>totsk addandtsk create(when using-a) and thread it into worktree creation. - Implement default-base detection via
refs/remotes/<remote>/HEADwith als-remote --symref … HEADfallback. - Update
tsk closeto fetch the upstream’s remote-tracking ref before computing “ahead” count, and add tests for parsing/base selection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| README.md | Documents the new base-branch behavior and the --base flag, plus use-cases and command synopsis. |
| main.go | Implements --base, default base detection, and upstream refresh logic in close. |
| main_test.go | Adds tests covering --base, default-base detection, and remote/branch parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cavalle
left a comment
There was a problem hiding this comment.
LGTM This is what I meant. Thank you! I'd polish the README a bit, but not need to block things now, I can do it myself in a future PR (the changes I'd do go beyond the scope of this PR).
One thing though: Copilot is complaining about something I don't fully understand (same thing in all the comments, I believe). Could you please review and either address or dismiss the comments before merging?
non-flag arguments must always appear after flag arguments Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@cavalle for reference: the documentation had non flagged arguments appear before flagged arguments, which causes the flagged arguments to be omitted. Example: tsk add <repo-path> [<repo-path> ...] [-b <branch>] |
non-flag arguments must come after flagged arguments Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
e7ba82f to
bc6e747
Compare
Summary
tsk addandtsk create -a ...now accept--from <branch>to base the new worktree's branch onorigin/<branch>instead of the hardcodedorigin/main.--from(see below).This is the multi-repo equivalent of
git checkout -b Bwhile sitting on branch A — useful when a task stacks on top of a feature branch that has not been merged to main yet.When
--fromhelpsmain. Branching off their feature branch keeps your diff focused on your own work instead of dragging in theirs, and avoids the "merge their branch into mine, then rebase later" dance.develop(or similar) before promotion, base new worktrees there so each task starts from the state the integration branch is actually in.Test plan
go vet ./...go test ./...(covers the new--frompaths inmain_test.go)tsk create <ref> <slug> --from develop -a <repo1> <repo2>— worktrees branched offorigin/develop(verified via merge-base + file content)tsk add --from main <repo>from inside a task subdir — worktree branched offorigin/main(different sha fromorigin/develop)--from) still bases onorigin/main— regression checktsk closewithout--forcerefuses worktrees with no upstream (thebranch.autoSetupMerge=falseinvariant survives the change)🤖 Generated with Claude Code