Forking this template
Starting a product? The quickstart puts every step in order; this page holds the details.
ModelRails is an upstream template: you clone it to start a product, build in fork-owned files, and periodically merge upstream improvements back in — the same workflow commercial Rails templates like Jumpstart Pro use.
Three things make the merges cheap:
- Shared git history — your app is a true clone, so merging a template
release (
bin/sync) is an ordinary merge. - Fork-owned files — everything you are expected to rewrite (marketing pages, brand strings, your routes, your docs) lives in files upstream never edits again.
- A merge driver — fork-owned paths are marked
merge=oursin.gitattributes, so when both you and upstream changed one, the sync keeps your version (details in Fork-owned files).
Is this model right for you? If you just want a starting point and never
plan to pull template improvements, skip the machinery: clone, delete the
upstream remote, and own everything (the thoughtbot Suspenders model). This
guide earns its keep when you want upstream fixes and features flowing into
your app for years.
Two pieces of shared machinery already update the easy way — the design system
(modelrails_ui) and the docs engine (markdowndocs) are gems, so improvements
to them arrive via bundle update, no merge involved. The merge workflow covers
everything else: the application code around the gems.
Start a new app
Clone the template under your product’s name and run bin/fork:
gh repo clone dschmura/modelrails_base my_app
cd my_app
mise install # the Ruby in .tool-versions, plus the deploy tools
bin/fork
bin/fork runs before bin/setup. It asks for:
- the project name (default: the folder’s name, snake_cased),
- the display name people see (default: the project name, capitalized),
- the tenancy preset,
- the support address users write to,
- the domain the app will live at, which becomes
RAILS_HOSTinconfig/deploy.yml(blank leaves it for later), - whether to create the GitHub repo, its owner (you or one of your organizations), and whether it’s public (the default) or private,
- whether a second person approves PRs (default: no, you merge your own).
A clone checks out next, the template’s integration branch, which can be ahead
of its last release. So bin/fork first moves next to the newest release
tagged on the template’s main, and your product starts from released code.
Then it does the remote surgery and the identity rename in one commit, records
the name, preset, template and release in .fork.yml, creates the GitHub repo with gh, pushes next,
and protects the branches with bin/branch-rules — in that order, so the rules
never land before your rename does. It prints each step as it runs, so you
can read what it did, and finish by hand if you ever need to. Without the gh
CLI, it lists the GitHub steps instead.
bin/fork --name my_app --display-name "My App" --preset personal --support-email help@my-app.com --domain app.my-app.com --github YOU --yes
bin/fork --dry-run # print the plan, change nothing
Under --yes, bin/fork doesn’t ask for the display name: it takes
--display-name, or capitalizes the project name. It can’t contain " or \.
Under --yes nothing is created or pushed on GitHub unless you pass --github (--github ORG
or --github ORG/name picks the owner and the repo’s name). --private makes a
private repo; GitHub’s free plan can’t apply branch rules to one, so bin/fork
warns and, when it can ask, offers to make it public instead. --team requires one approval
on every PR. A blank support address keeps a support@my_app.example
placeholder, and the fork’s CI fails until you set a real one.
Moving next to the release:
- fetches the template’s tags first; offline, it uses the releases the clone already knows;
- says so and keeps
nextas cloned whenmainhas no release tag; - says so and moves nothing when
nextis already at the release; - refuses when
nexthas commits the template doesn’t, since moving would drop them; - never runs on a checkout that is already renamed, or whose
originis your own repository (the Fork-button path), because movingnextback there would make its push fail.
--from-next skips the move and forks next as cloned, unreleased template
work included. It’s for template contributors trying unreleased changes.
It refuses to run on a dirty working tree: the identity rename wants to be one
clean commit you can always find again. Re-running is safe — it detects what is
already done, completes a rename that was interrupted partway, and picks up
whatever is still missing: a real support address, and (when you answer yes, or
pass --github) the GitHub repo, the push, or the branch rules.
When run interactively it offers to run bin/setup for you, then prints its
next steps: the quickstart’s address, and bin/production-setup, which sets up
mail, encryption keys and fnox before your first deploy. Last, it offers to
start the app with bin/dev and open the quickstart. Under --yes, or when
stdin isn’t a terminal, it offers neither: scripted and CI runs stay fast and
predictable.
From an organization’s copy
The template is meant to be forked, and forks get forked: an organization keeps
its own synced copy under its own name, and products start from that copy. Clone
the copy the way you’d clone the template, and name it with --template:
git clone git@github.com:ORG/modelrails_base_mirror.git my_app
cd my_app
bin/fork --template git@github.com:ORG/modelrails_base_mirror.git
There origin is the template, so its GitHub parent would be one hop too far
and the script deliberately does not ask; bin/fork knows the template by
name — a remote ending in /modelrails_base — and --template extends that to
the copy. With the flag, an existing upstream equal to that URL counts as
configured, and an origin equal to it gets the same remote surgery as the
template itself. The match is URL equality, with or without .git, never a
looser name pattern: a repository of your own that merely starts with
modelrails_base is never mistaken for the template.
Not GitHub’s Fork button
Clone instead. A repository made with GitHub’s Fork button:
- starts from the template’s
next, not its latest release, sincenextis already on youroriginandbin/forkwon’t move a branch you’ve pushed; - arrives with no
main(the button copies only the default branch); - says “forked from” on GitHub, and aims every new PR at the template;
- can’t be made private while it’s a fork of a public repository;
- starts with Dependabot alerts and security updates turned off.
If you haven’t built anything on it yet, delete it and follow
Start a new app. bin/fork warns when it finds this case:
origin is a GitHub fork.
If you’re keeping it, clone it and run bin/fork:
git clone git@github.com:YOU/my_app.git
cd my_app
bin/fork
Answer yes to Push next to origin and protect it? (or pass --github with
--yes). bin/branch-rules creates main from next once the rename is
pushed. Then, on GitHub:
- Settings → General → Leave fork network. PRs then default to your own
repository, and you can make it private. Leave after
bin/fork: it asks GitHub for the parent to record the template, andbin/syncreads that record, not the fork network. - Turn on Dependabot alerts and security updates in the security settings.
How the template gets recorded: your clone’s origin is already your product
and there is no upstream yet. Git has no record of what a fork was forked
from, but GitHub does. So when nothing else names the template and the gh CLI
is installed, bin/fork asks GitHub for origin’s parent and records that URL
in .fork.yml: the repository you pressed Fork on. bin/setup reads the URL
and adds it as the push-disabled upstream in every clone. Without gh, or
when GitHub reports no parent, name the template yourself with
--template URL; an explicit flag always wins over the lookup.
By hand (what bin/fork does)
Use this if you’d rather drive it yourself, or to finish up after an interrupted run:
# The template becomes a read-only "upstream" remote
git remote set-url --push origin DISABLED # before the rename, so no window exists
git remote rename origin upstream # a stray `git push upstream` now fails loudly
git branch --unset-upstream # or `git pull` would still pull the TEMPLATE
# Your new repository becomes origin (create it EMPTY on GitHub: no README, no license)
git remote add origin git@github.com:YOU/my_app.git
git config remote.origin.gh-resolved base # gh otherwise acts on upstream: the template
git config remote.pushDefault origin # gh otherwise offers the template first for an unpushed branch
git push -u origin next
bin/branch-rules --solo # only after the push: the rules then refuse direct pushes
# Activate the fork-owned merge driver (bin/setup also does this for you,
# but doing it now means your very first merge is already covered)
git config merge.ours.driver true
Then work through the identity-rename table below.
Two things you’ll notice afterwards, both intentional:
git remote -vshows upstream’s push URL asDISABLED. That string is not a real URL — it makes any accidentalgit push upstreamfail loudly instead of writing to the template.- Your branch tracks your own repo’s copy, so plain
git pullstays inside your app. Upstream only enters when you runbin/sync(Pull upstream updates).
.fork.yml’s template_baseline records the template commit you started from,
and template_release names its release, which answers “which template version
is my_app based on?” forever. A fork made with --from-next, or from the Fork
button, has no template_release.
Why not GitHub’s “Use this template” button, or a GitHub fork? “Use this template” squashes the entire history into one unrelated commit — every later merge of a template release would need
--allow-unrelated-historiesand conflict on everything both sides touched. A GitHub fork keeps the history but makes the template its parent, so pull requests default to the template, and GitHub will not fork a repository into the account that already owns it. Clone + re-pointed remotes gives you a standalone repo and mergeable history.
Every teammate who clones your new repository runs bin/setup — and only
that. They must not run bin/fork; the identity rename is already committed, and
bin/fork will tell them so and send them here.
git clone git@github.com:YOU/myapp.git
cd myapp
bin/setup
bin/setup reads .fork.yml and does the per-clone work: adds the upstream
remote (push disabled), activates the merge driver, points gh at your fork,
and writes the fork’s recorded tenancy preset into their .env. Those are
per-clone, not per-fork, which is why they live in setup rather than in the one-time script.
It also installs the git hooks (see Before You Push);
a clone that skipped bin/setup checks nothing until CI does.
Teammates need read access to the upstream template repository for the remote to be useful. If your template is private, grant it before they try to merge upstream — the remote will be added either way, but fetching will fail.
To verify the driver on any clone: git config merge.ours.driver should print
true. If it prints nothing, fork-owned files will conflict like ordinary files
on your next sync.
Rename the identity
Do this before your first commit, so the rename is one clean commit you can always find again.
| What | Where | Notes |
|---|---|---|
| Ruby module name | config/application.rb (module ModelrailsBase) |
bin/rails app:update won’t do this for you |
| Kamal service name | config/deploy.yml (service:) |
Tags Docker containers; collides if two apps share a host |
| Docker image name | config/deploy.yml (image:) |
Must match your registry path |
| Storage volume names | config/deploy.yml (volumes:) |
Renaming later orphans the old volume — do it before first deploy |
| Brand strings | config/locales/en/brand.en.yml |
Product name, description, copyright — fork-owned, one file |
| Brand colors | config/locales/en/brand.en.yml’s visual twin: app/assets/tailwind/tokens/_brand.css |
Optional — swap the primary palette family here (the file’s header says how); re-prove AAA in CI. Pages inside a workspace keep the workspace’s own color (what _brand.css does not reach) |
| Brand mark | app/views/shared/_site_mark.html.erb (one <svg>, nothing else) + the icon set in public/ |
Replace wholesale; keep fill="currentColor", aria-hidden="true", and a viewBox with no width/height (Extending) |
| Vocabulary | config/vocabulary.local.yml |
Your names for workspace and project (singular + plural); every template string follows (i18n) |
| Marketing copy | config/locales/en/pages.en.yml + app/views/pages/ |
Fork-owned — rewrite wholesale |
| Operations pages | app/helpers/operations/fork_nav_helper.rb |
Return your own operations pages as [label, path] pairs; the operations nav lists them after the template’s, with the same current-page cue |
| Languages | config/application.rb (config.i18n.available_locales) |
Register a locale here before adding its files, or I18n.t(locale:) raises in production — see Internationalization |
| PWA app name | public/manifest.webmanifest (name / short_name) |
Shown on the home screen if users install the PWA |
| CI image tags | .github/workflows/docker_build.yml, image_scan.yml + hotcell_image_scan.yml (tags:) |
Local-only build tags; cosmetic but confusing if stale |
| Devcontainer bundle-cache volume | .devcontainer/devcontainer.json |
Optional; the invariant spec only checks the bundle-cache suffix |
| Fork provenance | .fork.yml |
Written by bin/fork: your name, tenancy preset, the template’s URL, and the template commit and release you forked from. Committed so every clone inherits the decisions — bin/setup reads the preset and the template’s URL, the app reads the preset at boot outside tests, and bin/sync and bin/release read the template’s URL. The suite reads its presence as “this is a fork”: it then runs the specs tagged :fork_only (today, the placeholder-support-address check) and leaves out those tagged :template_only, among them the check that bin/fork’s rename targets still exist upstream. Everything else is derived from the repository |
| Session cookie key | optional config/initializers/session_store.rb |
Only if multiple forks will share a cookie domain |
Then verify nothing was missed:
grep -ri modelrails . \
--exclude-dir={.git,tmp,log,coverage,storage,vendor}
bin/parallel-rspec
Expected leftovers: references to the modelrails_ui design-system gem
(Gemfile, .modelrails_ui/, generated component comments) — that’s the
library’s name, not your app’s. Lookbook preview sample copy under
spec/components/previews/ also mentions ModelRails; rename it or leave it,
nothing asserts on it. The full test suite and CI’s production-image build are
the rename’s safety net.
Bootstrap secrets and configuration
The template ships zero encrypted credential blobs — your fork generates its own on first edit:
bin/rails credentials:edit --environment development
bin/rails credentials:edit --environment production
bin/mail-setup handles the mail half of this: it creates the production credentials if
they don’t exist, adds the provider’s login, and updates config/deploy.yml.
Add OAuth keys and mailer.from (structure in Local Development),
and to production the mail provider’s login as smtp.user_name and smtp.password
(Deployment) and, once
backups go to a bucket, its key as object_storage.access_key_id and
object_storage.secret_access_key (Backups).
Commit your .yml.enc files; the .key files stay gitignored. Kamal builds the
image from a clone of the commit, so an uncommitted credentials file never
reaches production, and the app refuses to boot without it. .kamal/secrets
takes RAILS_MASTER_KEY from the deploying environment, else reads
config/credentials/production.key.
Personal data — email addresses and names — is encrypted at rest with Active Record Encryption, and production refuses to boot without the keys. Generate them once and paste the block into the production credentials:
bin/rails db:encryption:init
bin/rails credentials:edit --environment production # paste the active_record_encryption block
Development and test read literal keys from config/environments/development.rb
and test.rb — a fresh clone and CI run with no secrets, and that data is
disposable. Rails applies those settings over credentials, so keys added to
development credentials are ignored until the environment-file lines are
removed. The deterministic_key has no rotation path in Rails: back it up
wherever the credentials key is backed up, because losing it loses every
email lookup. Which columns, and why some are deterministic:
Security.
For production you’ll also set RAILS_HOST (unless you gave bin/fork a
domain) and choose a signup mode — see .env.example, Presets, and Deployment. The tenancy
preset needs nothing more: production uses the one bin/fork recorded in
.fork.yml, and a WORKSPACE_ON_SIGNUP set in the environment overrides it.
Protect the branches
The template’s default flow uses three branches:
| Branch | Role |
|---|---|
next |
Integration, and the default branch: every feature PR targets it. Deploys nowhere. |
release/<name> |
A release, cut from next by bin/release cut and deployed to staging for review. Fixes and reverts land on it by PR. |
main |
Production. Takes a release by PR, with merge commits only. |
bin/fork runs this for you once your rename is on GitHub. To run it yourself,
or to change your mind later:
bin/branch-rules # one approval on every PR
bin/branch-rules --solo # no approval: you merge your own PRs
It creates whichever of main and next is missing from the other (after
bin/fork, that’s main), makes next the default branch, turns on
auto-merge (a PR, yours or an agent’s, can be queued to merge once its checks
pass; the rules still apply), then applies
the rulesets in config/github/rulesets/. Under those rules, next,
release/** and main take changes only by PR, and only after static and
test pass on an up-to-date branch. Rerunning it updates the rulesets in
place. It names any other ruleset on the repo, which you reconcile by hand.
- Push first. Once the rules apply, a direct push to
nextormainis refused. --soloexists because GitHub refuses an approval from a PR’s own author.- No one bypasses. A bypass, even “through pull requests only”, lets an admin’s ordinary merge skip the approval and the up-to-date check, and nothing asks first.
- After anything lands on
main, merge it back intonextwithbin/release merge-back, which goes through a branch cut frommain. A PR whose head ismaincan’t be brought up to date, since that would push tomain. - Plan limits. GitHub Free applies rulesets to public repositories only. On a private one the script reports each refused ruleset and exits non-zero.
- Turn on Dependabot alerts and security updates in the repository’s
security settings. A repository made with GitHub’s Fork button starts with
both off, so
.github/dependabot.ymlalone opens no PRs. - When bundler-audit goes red between syncs, a new advisory has landed
against a gem you already have. Bump only the gems it names:
bundle update --conservative <gem> <gem>, then rerunbin/bundler-audit.
Cutting, reviewing and shipping a release, hotfixes, and the merge-back are in Releasing. To change the flow, edit the JSON files, or replace the script.
Fork-owned files
These paths are yours. Upstream froze them the day the seams shipped and will
never meaningfully change them again; the merge=ours driver keeps your version
on every sync.
| Path | What goes there |
|---|---|
config/locales/en/brand.en.yml |
Product name, description, copyright |
config/locales/en/pages.en.yml |
Marketing copy for your pages |
app/views/pages/**, app/controllers/pages_controller.rb |
Your marketing/static pages. A layout of your own for them must render shared/toasts: email verification lands on / with its message |
spec/system/pages/**, spec/requests/pages_spec.rb |
The tests for those pages — rewrite them with the pages |
config/routes/app.rb |
Your product’s routes (loaded by draw(:app)) |
.rubocop/app.yml |
Your RuboCop overrides — turn a house cop off here, with the reason (below) |
config/markdowndocs_categories.local.yml |
Registers your own docs pages on this /docs index |
app/assets/tailwind/tokens/_brand.css |
Brand-color overrides — swap the primary palette family (the file’s header says how) |
app/views/shared/_site_mark.html.erb |
The brand mark — a file that is one <svg> (Extending) |
public/icon.svg, public/icon.png, public/icon-192.png, public/icon-512.png, public/apple-touch-icon.png, public/favicon.ico |
The favicon and PWA icon set — same artwork, same filenames and sizes (Extending) |
config/vocabulary.local.yml |
Your product’s nouns — any subset; config/vocabulary.yml fills the rest (i18n) |
app/helpers/operations/fork_nav_helper.rb |
Your own operations pages for the operations nav, as [label, path] pairs |
config/initializers/project_tools.rb |
Register your own project tools (ProjectTools::Registry.register) — see Extending: Project Tools |
config/required_production_config.local.yml, config/credentials/production.local.yml.example |
Your own production inputs, described in the catalog’s format (never their values), and the credentials example file generated from them |
README.md |
Your product’s README |
Clientside (external client area). Clientside is available in every preset and is enabled per-project, not per-deployment — a fork enables it on a project-by-project basis via the project’s Clientside settings toggle. No fork-owned file change is required to activate it; the toggle is in the project settings UI. See Clientside for details.
Vocabulary — you own the words, upstream owns the sentences
The template’s copy never says “workspace” or “project”; it says %{workspace}
and %{project}, and a boot-time hook fills those from config/vocabulary.yml.
To rename, put your words in config/vocabulary.local.yml:
workspace: { singular: "course", plural: "courses" }
project: { singular: "team", plural: "teams" }
Restart. Every template string, including the ones upstream adds next month,
arrives in your words — that is the point of this file existing instead of
you editing workspaces.en.yml. Two template specs keep it true: no locale
value under config/locales/en/ may spell out the bare noun (brand and
pages excepted — those are yours to word), and every interpolation token must
be supplied. That first rule covers the files you add, so write your own
strings with %{project} too and they follow the rename the same way.
What it does not do. It does not rename models, tables, routes, or URLs —
those stay workspaces and projects, and a product whose UI says Course and
whose URL says /workspaces/3 is the accepted shape. It does not touch the
user docs under app/docs/user/, which are markdown, not I18n; rename those
by hand. And it never adds an article: template strings are worded so no “a”
or “an” precedes a noun, and your own strings should be too. It does not
escape: a fork’s noun lands unescaped in _html keys, which is fine for a
boot-time file only the fork edits and never a place for user input.
Unlike pages.en.yml, this file holds nothing upstream will ever change, so
merge=ours here carries none of the silently-missed-fix risk described above.
Fork seams — method overrides
Beyond file-level seams, a handful of private methods are designed to be overridden in ApplicationController (or a concern it includes). These are stable hooks upstream won’t break.
authenticated_home_path
Every post-auth landing routes through this single private method: SessionsController, magic-link verification, OAuth callback, registrations, and redirect_if_authenticated. The default is root_path.
Override it to send signed-in users somewhere other than root:
# app/controllers/application_controller.rb
private
def authenticated_home_path
dashboard_path # or workspaces_path, events_path, etc.
end
This is the primary seam for Workspace-optional (:none) apps, where post-sign-in landing should be a workspace-agnostic home (a user profile, an event listing, a personal dashboard) rather than a workspace context. But it’s useful for any preset — even Solo-default forks often want to land users on /dashboard instead of /.
Tuning knobs you own
These constants are yours to change and are not merge-frozen: an upstream change to them will conflict on sync, which is the point — you decide.
NotificationPreferences::ALLOWED_RETENTION_DAYS— the retention choices offered (app/lib/notification_preferences.rb)NotificationPreferences::DEFAULT_RETENTION_DAYS— the fallback for a row whoseretention_dayskey is absent; the column default indb/schema.rbis what a new user actually gets — change both, or the column default winsNotificationPreferences::NEVER_CAP_DAYS— what a pre-PR-5 “Never” choice reads asActivityLogRetentionSweepJob::SECURITY_RETENTION_FLOOR— how long credential-event audit rows are kept, regardless of the general windowhotcell/config.rband the Hot Cell accessory’scpus/memory— the sandbox’s limits, sized to your host (Hot Cell, Tune it)
Turning a house cop off in your fork
Base ships eight house cops under lib/rubocop (ModelRails/*), configured in the base-owned .rubocop/house.yml and on by default. They are rules about how base writes code — the same kind of thing as the omakase config it inherits — and your fork is free to disagree with any of them. Do it in the fork-owned .rubocop/app.yml, which upstream never touches (merge=ours), with the reason on the line above:
# Our admin area keeps a few verb routes on purpose; see ADR-7.
ModelRails/RestfulActions:
Enabled: false
That is a decision with a name, which is what a reviewer or an agent reads first. It is not the place for offenses in code you inherited or wrote before a cop landed: those belong in .rubocop_todo.yml, which grandfathers by path and shrinks as files are fixed, while app.yml changes the rule itself. Never edit .rubocop/house.yml or .rubocop.yml in a fork; both are base-owned and every upstream sync would conflict.
How the merge driver actually behaves
The merge=ours driver is a conflict resolver, not a wall. During a sync:
- You customized the file, upstream changed it too → the driver keeps your version, silently — no conflict shown. This is the common case: you rewrite all of these paths early, that’s why they’re on the list.
- You never touched the file, upstream changed it → upstream’s version flows in normally. The driver only runs when both sides changed a file.
Two consequences worth understanding:
You can silently miss upstream fixes. If upstream patches a bug in a file
you’ve customized (say pages_controller.rb), your next sync keeps your version
and the fix never arrives — with no warning. The update recipe below includes a
one-command check for exactly this.
This has already happened once, so here is the worked example. Until 2026-08-04
the template shipped its maintainer’s real support address in
config/locales/en/pages.en.yml; PR #549 (7fe2fa87) replaced it with a
placeholder. That file is fork-owned — the forking guide tells you to rewrite it
wholesale — so every fork created before that date keeps the old address on
every sync, silently, indefinitely. Two ways to catch this class of miss:
-
At sync time — the fork-owned-paths check in the update recipe below (
git log --oneline main..upstream/main -- config/locales/en/pages.en.yml …) lists upstream commits that will not flow in. It only works before you merge: afterward the commit is in your history even though its content never reached your file. -
Any time after — grep for the concrete leftover. For this instance:
git grep -n "modelrails.dev" config/localesA hit means you are still shipping the template’s address; replace it with your own. Forks created (or re-synced) after the fix also get a durable guard — a fork-gated template invariant fails the suite while any placeholder support address survives.
The driver must be active. bin/setup activates it on any clone that has an
upstream remote. Without it, these paths conflict like ordinary files — verify
with git config merge.ours.driver → true.
db/seeds.rb is shared ground rather than fork-owned: everything above the
“Fork seam” marker at the bottom is template-owned; add your domain seeds below
the marker.
Adding your own docs page
Drop app/docs/my-feature.md (same frontmatter as this file), then create
config/markdowndocs_categories.local.yml:
My Product:
- my-feature
Categories named like template ones (“Guides”, “Features”) append to them; new names become new index sections. The docs-coverage spec keeps guarding orphaned pages across both maps automatically.
Pull upstream updates
bin/sync
bin/sync brings the template’s newest releases into your next, as a PR:
- It finds the template’s releases that your
nextdoesn’t have yet. - It merges the latest one on a
sync/template-v<name>branch. - It keeps your
CHANGELOG.md, and writeschangelog.d/template-v<name>.mdwith one line for each release it brings in, linking that release’s notes on the template’s GitHub releases page. - It pushes the branch and opens a PR into
nextthat merges itself, with a merge commit, once its checks pass. Merging it starts your next release like any other PR.
bin/sync brings in releases only, not the template’s work in progress: a fix
merged into the template reaches your fork once the template ships it in a
release. If next already has the template’s latest release, it says so,
counts any template changes not released yet, and stops.
It needs a clean working tree, an upstream remote (bin/setup adds it) and
the GitHub CLI, signed in. Like bin/setup, it points gh at your fork, not
the template, so a clone set up before setup did that is fixed on its next sync.
A fork made before bin/sync existed doesn’t have it yet. Its first sync
brings it in, so run that one from the template’s copy. It needs the
release_flow gem, which that sync adds to your Gemfile:
git fetch upstream
gem install release_flow
d=$(mktemp -d); mkdir -p $d/bin $d/lib
for f in bin/sync lib/clean_git_env.rb lib/github_origin.rb lib/fork_config.rb; do git show upstream/main:$f > $d/$f; done
ruby -e "load '$d/bin/sync'; Sync.new(root: Dir.pwd).run"
Once its PR merges, every later sync is bin/sync.
Don’t merge the template by hand. Your changelog and the template’s share a
file but not their releases, and git’s union merge files the template’s lines
into your shipped releases without a conflict. CI refuses that
(bin/release check), and bin/sync exists so you never have to undo it.
Merge sync PRs with a merge commit, never a squash: the merge is how the next
bin/sync tells what you already have.
1. Look before you sync
git fetch upstream
git log --oneline origin/next..upstream/main # what's coming
git log --diff-filter=R --stat origin/next..upstream/main # what moved — plan renames, don't discover them mid-merge
Read the template’s release notes on its GitHub releases page: breaking changes
and migrations are called out there. If a change sounds structural (schema,
deploy.yml), read its PR before syncing, not after.
Then check whether upstream touched files you own — those changes will NOT arrive through the merge (the driver keeps yours):
git log --oneline origin/next..upstream/main -- \
app/views/pages app/controllers/pages_controller.rb \
config/locales/en/pages.en.yml config/locales/en/brand.en.yml \
config/routes/app.rb config/markdowndocs_categories.local.yml \
config/initializers/project_tools.rb \
app/assets/tailwind/tokens/_brand.css README.md
If a commit there looks like a fix you want, cherry-pick it after the merge:
git cherry-pick <sha>, then adapt it to your version of the file.
2. If it stops on conflicts
bin/sync stops and names the files, with CHANGELOG.md already done. Resolve
each one, git add it, then run bin/sync again: it commits the merge, pushes
and opens the PR.
| Conflict in | Resolution |
|---|---|
CHANGELOG.md |
Never — bin/sync keeps yours before it stops |
| Fork-owned paths | Shouldn’t happen — the driver keeps yours. If it does, the driver isn’t active: git merge --abort, run git config merge.ours.driver true, then bin/sync again |
Identity values (config/deploy.yml service/image/volumes, SMTP_*, MAIL_FROM, RAILS_HOST; config/application.rb module) |
Keep your values; take any structural changes around them. Taking theirs on SMTP_ADDRESS puts the old host beside your new login, and the boot check can’t see that |
Gemfile |
Keep both sides’ gems, then regenerate the lockfile |
Gemfile.lock |
Never hand-merge: git checkout --theirs Gemfile.lock, then bundle install, commit the regenerated result |
| Behavior (app code, specs, config) | Take theirs — unless you deliberately diverged, in which case consider sending your version upstream instead |
| Two migrations, same timestamp | Keep both; rename yours to a later timestamp with git mv, then re-run bin/rails db:migrate |
db/schema.rb |
Never hand-merge: git checkout --theirs db/schema.rb, then bin/rails db:schema:regenerate, which rebuilds it from both sides’ migrations |
| Upstream renamed/moved a file you’d edited | Re-apply your edit at the new location, delete the old file. If the same resolution recurs every sync, turn on git config rerere.enabled true so git replays it for you |
A conflict looks like this — your side on top, upstream’s below:
<<<<<<< HEAD
primary_cta: "Start organizing your photos"
=======
primary_cta: "Get started free"
>>>>>>> 9f3c2e1 (the template's release)
Decide which line the file should have (here it’s your marketing copy — keep
yours), delete the other line and all three marker lines, then git add the
file. That’s the whole skill; the doctrine table tells you which side to favor.
3. Prove it
CI runs the suite on the PR. Locally, on the sync branch:
bin/rails db:migrate # upstream may ship migrations
bin/parallel-rspec
bin/parallel-rspec is the full-suite command the Quickstart and CI use; see
Three ways to run the suite.
If something looks wrong after the merge
- A fork-owned file changed unexpectedly — the driver wasn’t active during
the merge. Restore your version from before the sync:
git restore --source=origin/next <path>, commit, then fix the driver config. - Bundler errors — regenerate instead of debugging the lockfile:
git checkout --theirs Gemfile.lock && bundle install. - Tests fail — run the failing spec alone, then
git diff upstream/main -- <file>on the code it covers to see whether your divergence or the upstream change broke it.
Cadence
Run bin/sync often — don’t bank up months of drift. Small frequent merges
conflict less than one big annual one; if upstream is busy, a fixed weekly
sync keeps every merge boring.
Contribute a fix back
Make template-worthy fixes in a checkout of modelrails_base itself (branch →
PR), not in your app — upstream is push-disabled by design. If the fix already
exists as a commit in your app:
cd ../modelrails_base
git checkout -b fix/thing main
git remote add myapp git@github.com:YOU/myapp.git # or ../myapp for a local checkout
git fetch myapp
git cherry-pick <sha>
Three guardrails before you open the PR:
- Only template-owned files. If the commit also touches fork-owned paths (your README, pages, brand strings), it would pollute the template — split the commit, or port the change by hand instead of cherry-picking.
- Regular commits only, never merge commits — cherry-picking a merge commit
needs
-mand rarely does what you meant. - Strip anything product-specific (names, copy, config values) so the change reads as a template improvement.
Stay mergeable
- Prefer new files to edited template files — new files merge clean by definition. New models, controllers, components, initializers, docs pages: all conflict-free.
- Brand strings only in
brand.en.yml— if you find one hardcoded anywhere else, that’s an upstream bug; report or fix it upstream. - Product routes only in
config/routes/app.rb— leaveconfig/routes.rbto the template. - Gemfile: add, don’t pin. Append your gems with loose constraints
(
"~> 1.0"); pinning exact versions or git branches conflicts with upstream’s dependency bumps every sync. - Treat
UI::*primitives as upstream-owned — extend by composing new components rather than editing the primitives; the planned design-system update engine will regenerate them. - Layouts and shared partials are template-owned but not frozen. Adding a nav link to the header partial is fine — insert lines, don’t restructure, so a future conflict has one obvious resolution.
- When you must edit any template file (an initializer,
application.rb), make the edit additive — append rather than rewrite. .github/is template-owned and churns weekly — 33+ action refs are SHA-pinned and bumped by grouped Dependabot PRs (gem bumps arrive the same way, one grouped PR a week), and the suite’s pin invariant fails on ANY unpinneduses:(yours included). Add fork CI as new workflow files, SHA-pinned with the# <tag>trailer the invariant reads; never edit the template’s workflows in place.- Dependabot never bumps
modelrails_ui, by config. For a gem pinned by git tag, Dependabot keeps the lockfile SHA as the current version, so its default cooldown can propose the newest tag older than the pin as an update — it did, three times. The bundler block ignores the gem; a bump is a hand PR that diffs each vendored component against the tag it came from before regenerating (see Components). The suite’s invariant fails if the ignore is removed. Rails andrspec-railscome from git commits too, and are ignored and moved by hand the same way (see Local Development). - Fetching a URL a user typed? Read the outbound-request (SSRF) posture in Security first — the template deliberately ships no fetch-by-URL feature, and the first fork that adds one owns the pinning.