Skip to content

Add 'mob start --create-base <branch>' to automatically create base branch and open mob branch - #489

Open
ruben-carvalho wants to merge 3 commits into
remotemobprogramming:mainfrom
ruben-carvalho:feature/start-from-main
Open

ruben-carvalho wants to merge 3 commits into
remotemobprogramming:mainfrom
ruben-carvalho:feature/start-from-main

Conversation

@ruben-carvalho

Copy link
Copy Markdown
Contributor

When working with feature branchs and PRs starting a mob on a new story is always the same ritual: checkout main, pull, create the feature branch, push it with upstream set, and only then mob start. We ended up writing a wrapper script to automate this because mob itself had no way to create the base branch. mob start --create assumes you already created and checked out the branch, and getting there requires an up-to-date local main.

What this adds: mob start --create-base does the whole thing in one step:

fetches and detects the remote default branch (origin/HEAD, falling back to main/master)
creates directly from origin/. The default branch doesn’t need to be checked out locally, or even exist locally pushes it with upstream set and starts the session on the wip branch mob/

It refuses to run when you’re on a wip branch, when the branch already exists locally or on the remote, or when it can’t find a default branch. A dirty working tree is handled the same way as plain mob start, with --include-uncommitted-changes / --discard-uncommitted-changes. --create-base implies --create, can’t be combined with --join, and aborts with a hint when no branch name is given.

Added integration tests on the git testbed, help text, and a CHANGELOG entry.

@gregorriegler

Copy link
Copy Markdown
Collaborator

Thanks a lot for this, @ruben-carvalho, and for the thorough tests!

This has come up before in #211, which proposed exactly this and went through quite a bit of discussion. There we agreed on extending the existing flag rather than adding a new one:

mob start --create [<branch>]

We shipped it in two steps. The first, mob start --create without a name, landed in #304 and only pushes the current branch. The second, passing a branch name, was postponed, so your PR is effectively that second step. We'd like to follow the design from #211 rather than add --create-base:

  • Reuse --create, no new flag. People already try --create <name> today and end up with a 0-minute timer (Is it expected of create flag? #342).
  • Branch off where you are, no default-branch detection. Create the new branch from the current branch's up-to-date remote (git checkout -b <branch> --no-track origin/<current> after the fetch). Then we don't need the origin/HEAD and main/master fallback logic.
  • Don't refuse if the branch already exists. If it exists on the remote, check it out. If it exists locally, switch to it. Then everyone in the mob can run the same command. Mob already refuses to start when the base branch has unpushed commits and only fast-forwards, so a diverged local branch still stops with an error and no commits are lost.

These are the invocations we'd need to support (-c and --create are interchangeable):

Existing, must keep working:

mob start 10
mob start -c
mob start -c 10
mob start 10 -c

New:

mob start -c feature
mob start -c feature 10
mob start 10 -c feature

Ambiguous, a number after -c stays the timer:

mob start -c 10          → create + 10-minute timer, not a branch named 10
mob start -c 1234        → same; purely numeric branch names can't be created this way

Invalid, should fail with an error:

mob start -c 10 feature  → probably meant `-c feature 10`

So after -c, the next argument is the branch name only if it doesn't start with - and isn't a number.

This should make the change much smaller than the current diff. Would you be up for reworking the PR in this direction? Happy to help if anything is unclear.

@ruben-carvalho

Copy link
Copy Markdown
Contributor Author

Hi, thank you for the answer! Sure I'll take a look and change accordingly. My proposal stated that we wouldn't even need to be on the default main branch to run the command, but maybe that's an overstep and we should still checkout the branch where we want to create the base and mob branch off.

Will update this soon!

ruben-carvalho and others added 2 commits November 18, 2026 11:43
…se branch from updated remote default branch and create the mob branch right from it

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
As discussed in the review and in remotemobprogramming#211, 'mob start --create' now takes
an optional branch name instead of introducing a new --create-base flag:

- After -c/--create, the next argument is the branch name only if it
  does not start with '-' and is not a number (a number stays the
  timer, so 'mob start -c 10' keeps working).
- The branch is created from the current branch's up-to-date remote
  (git checkout -b <branch> --no-track origin/<current>), with no
  default-branch detection.
- An existing branch is no longer refused: a local branch is switched
  to, a remote one is checked out, so everyone in the mob can run the
  same command. A diverged local branch still stops with the existing
  unpushed-commits error.
- 'mob start -c 10 feature' fails with an error suggesting
  'mob start --create <branch> <timer>'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ruben-carvalho
ruben-carvalho force-pushed the feature/start-from-main branch from 69e8402 to 744fe2b Compare November 18, 2026 14:00
@ruben-carvalho

ruben-carvalho commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed the changes preserving the command mob start -c and adding the optional branch name. Please take a look 🙂.

One question:
the “cannot create branch while on wip branch” guard only applies when the branch doesn’t exist yet. If it already exists (locally or on the remote), mob start -c from inside a running session silently checks it out and starts/joins that branch’s session, consistent with “everyone in the mob can run the same command”, but it does leave the current session without a mob done/mob next. Happy to make it refuse from a wip branch in both cases if you’d rather keep that symmetric.

Best,
Rúben

With --include-uncommitted-changes or --discard-uncommitted-changes,
start() stashed or hard-reset the working tree before the checks that
can refuse the branch given to --create (wip branch name, on a wip
branch, current branch without a remote, unpushed commits on the target
branch). A failing check then left the user's changes stashed, or
already discarded, without starting anything. Run all validations
first, and only then stash or reset and switch branches. The
unpushed-commits check on an existing local target branch now also runs
before the checkout, so a refused start stays on the original branch.

Also key the too-many-arguments error on a literally typed -c/--create
instead of configuration.StartCreate, so users with MOB_START_CREATE=true
and a stray extra argument don't get an error about a flag they never
typed, and restore the mocked exit via t.Cleanup in the new test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants