with one click
corp-web-japan-origin-main-worktree-safety
// Safely implement corp-web-japan changes from the latest origin/main when local main is dirty or behind, and avoid accidentally reverting recently merged metadata/title updates.
// Safely implement corp-web-japan changes from the latest origin/main when local main is dirty or behind, and avoid accidentally reverting recently merged metadata/title updates.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | corp-web-japan-origin-main-worktree-safety |
| description | Safely implement corp-web-japan changes from the latest origin/main when local main is dirty or behind, and avoid accidentally reverting recently merged metadata/title updates. |
| version | 1.0.0 |
| author | Hermes Agent |
| license | MIT |
| metadata | {"hermes":{"tags":["corp-web-japan","git","worktree","safety","metadata","seo"],"related_skills":["github-pr-workflow","test-driven-development"]}} |
Use this when working in corp-web-japan, especially for page metadata / SEO / route work where a stale local branch can silently overwrite recent merged changes.
In this repo, local main may be:
origin/mainIf you inspect files on local main first and then patch a fresh worktree later, you can accidentally revert recent merged changes such as finalized page titles.
Use this workflow when:
corp-web-japanmain is dirty or behind originCritical default for this user:
origin/main while leaving local main stale without calling that out.main baseline explicitly.main code and recent commits relevant to the feature area.Starting from origin/main is not enough by itself; you must also understand what changed on latest main.git branch --show-current
git status -sb
git worktree list
env -u GITHUB_TOKEN gh pr list --state open --limit 30
main before planning.git fetch origin main --quiet
git rev-parse origin/main
git log --oneline --decorate -n 20 origin/main
Then inspect the actual latest-main versions of the relevant files before deciding the plan, for example:
git show origin/main:src/app/blog/page.tsx | sed -n '1,220p'
git show origin/main:src/app/blog/[id]/[slug]/page.tsx | sed -n '1,260p'
This step is mandatory in fast-moving repos: codebase assumptions can become stale even within a few days.
If local main is dirty or behind, do NOT edit there.
Fetch, re-check the remote tip, and create a fresh worktree from origin/main.
Fetch and create a fresh worktree from latest main.
git fetch origin main --quiet
git checkout main
git pull --ff-only origin main
git worktree add .worktrees/<branch-name> -b <branch-name> main
If local main is intentionally left untouched for some exceptional reason, explicitly tell the user and still branch from the fetched latest origin/main.
Example:
git checkout main
git pull --ff-only origin main
git worktree add .worktrees/fix-issue-62-seo-baseline -b fix/issue-62-seo-baseline main
4.1 Validate that the new worktree is a real linked checkout before editing.
Do not assume any directory under .worktrees/ is a valid Git worktree just because it exists. Confirm all of the following:
git worktree list --porcelain
git -C .worktrees/<branch-name> branch --show-current
git -C .worktrees/<branch-name> rev-parse --show-toplevel
ls -la .worktrees/<branch-name> | sed -n '1,20p'
Expected signs of a valid linked worktree:
git worktree list --porcelaingit -C <worktree> branch --show-current returns the expected branch name.git file that points to the linked worktree metadatarev-parse --show-toplevel resolves through the linked checkout normallyIf the directory exists but is not registered as a worktree, do not edit there. Remove the stray directory and recreate the worktree properly.
.worktrees/fix-blog-28-toc-highlight for branch fix/blog-28-toc-highlight..worktrees/fix/... that are easy to misread and mis-target in later tool calls.main.git -C .worktrees/<flat-worktree-name> rev-parse HEAD
git -C .worktrees/<flat-worktree-name> rev-parse origin/main
git -C .worktrees/<flat-worktree-name> merge-base HEAD origin/main
For a fresh branch with no new commits yet, these should all match.
5.1 Verify that the checkout is materially complete, not just logically registered.
A practical failure mode in this repo: a path under .worktrees/ can appear to succeed during git worktree add, and git worktree list --porcelain can still show the entry, but the actual directory can end up containing only a tiny partial subtree instead of a real checkout.
Minimum filesystem sanity check before editing:
find .worktrees/<flat-worktree-name> -maxdepth 2 | sed -n '1,30p'
You should see a normal repository root shape such as src/, tests/, public/, package.json, and the linked .git file. If you only see a sparse fragment such as one nested directory or a handful of files, do not trust that worktree.
Recovery rule:
git worktree prune~/workspace/<repo>-<topic>This is safer than trying to salvage a half-populated checkout whose path name happens to match the intended worktree.
5.2 Prefer repo-external flat worktree paths when repo-local .worktrees/ paths behave strangely.
Practical fallback pattern:
git worktree add -b <branch-name> ~/workspace/<repo>-<topic> origin/main
Then verify with:
test -d ~/workspace/<repo>-<topic> && echo exists
git -C ~/workspace/<repo>-<topic> branch --show-current
git -C ~/workspace/<repo>-<topic> rev-parse --show-toplevel
find ~/workspace/<repo>-<topic> -maxdepth 2 | sed -n '1,30p'
Important extra lesson:
git worktree add success message by itselfread_file, patch, or follow-up shell command~/workspace/cwj-<topic>Only start editing after those checks pass.
5.3 After recreating a worktree because of this failure mode, discard the bad path entirely.
5.4 Also verify the new worktree really points at the expected base:
git -C .worktrees/<flat-worktree-name> rev-parse HEAD
git -C .worktrees/<flat-worktree-name> rev-parse origin/main
git -C .worktrees/<flat-worktree-name> merge-base HEAD origin/main
For a fresh branch with no new commits yet, these should all match.
A common cleanup follow-up in this repo is:
main is behind origin/mainmain has one meaningful uncommitted file changemain state forwardSafe pattern:
mainorigin/mainExample use case:
.agents/skills/** was edited during investigation on dirty local mainRecommended command flow:
git fetch origin --prune
git worktree add -b docs/<topic> ~/workspace/<repo>-<topic> origin/main
cp /path/to/dirty-main/<file> ~/workspace/<repo>-<topic>/<file>
git -C ~/workspace/<repo>-<topic> diff --stat -- <file>
Important rule:
main just because the uncommitted file already exists thereWhen the preserved change is a repo-local skill or guidance doc under paths such as .agents/skills/**, do not assume the backed-up text is still correct verbatim.
Use this validation flow before opening the PR:
Typical example:
/download/pdfPractical rule:
Before pushing or updating a PR branch:
git fetch origin main --quiet
git rebase origin/main
Use the latest main again as the final integration baseline. Do not skip this just because the branch originally started from latest main.
Practical same-session nuance learned from /t/events preview work:
origin/main can advance between worktree creation and your first push, even during a short task.git fetch shows HEAD, origin/main, and merge-base no longer match, rebase before the first push, not after opening the PR.main already landed a helper-path cleanup (for example @/lib/publications/event-publication-records -> @/lib/publications/events/records), keep the latest-main helper/import path and reapply only your intended UI/behavior change on top.Practical follow-up nuance:
git rebase origin/main will fail with cannot rebase: You have unstaged changes.Additional PR-head rewrite nuance:
gh pr view can briefly lag and still show the old commit list.git rev-parse HEAD
git ls-remote origin refs/heads/<pr-branch>
gh pr view has not caught up yet.git fetch origin --prune
printf 'HEAD '; git rev-parse HEAD
printf 'origin/main '; git rev-parse origin/main
printf 'merge-base '; git merge-base HEAD origin/main
origin/main; it is safe to commit the local change directly without doing a redundant pre-commit rebase.origin/main advanced or those SHAs differ.Add a small node test under tests/ that verifies:
layout.tsx defines metadataBaserobots.ts includes sitemap and hostsitemap.ts includes only real public routesnotFound() are excluded from the sitemapThis catches path drift such as /whitepaper vs /whitepapers and prevents accidental sitemap entries for non-live pages.
/whitepapers, not /whitepaper./events currently renders notFound(), exclude it from sitemap until the route is actually live.metadataBase, canonical generation, robots, and sitemap stay aligned.Run:
npm install
node --test tests/<new-seo-test>.test.mjs
npm run test:ci
npm run build
Notes:
npm run test:ci. If eslint is missing or node_modules/.bin/eslint does not exist, run npm install in that worktree first.node_modules, a temporary symlink from the worktree node_modules to the parent checkout can be enough to run npm run test:ci / eslint / tsc for verification.Symlink [project]/node_modules is invalid, it points out of the filesystem root. In that case, do not treat the symlink itself as a product bug. For local verification from that symlinked worktree, prefer next build --webpack instead of the default Turbopack build path.origin/main. If next build --webpack fails on the known corp-web-japan baseline CSS Modules issue in src/components/layout/site-header.module.css (:root selector is not pure), record it as an unrelated baseline rather than as a regression from the current PR.main implementation and recent commitsbranch created from origin/main as sufficient, without also reading the latest-main files that define the current behaviormain, then editing a separate worktree without re-reading files therenpm run test:ci fail early with sh: eslint: command not found.next build output under another worktree can confuse repo-wide ESLint/test runs and produce unexpected ENOENT reads against files that no longer exist in that sibling checkout. If npm run test:ci fails with an ESLint file-open error pointing into .worktrees/<other-branch>/.next/..., remove stale .next directories under the affected worktrees and rerun.notFound()origin/mainnpm run test:ci and npm run build pass