ce-worktree
Skill này làm gì
Skill này tạo một không gian làm việc tách biệt trên một nhánh mới hoặc có sẵn, để thư mục chính của bạn giữ nguyên. Dành cho lập trình viên làm nhiều tác vụ trong một repository.
Khi nào nên dùng
- ✓Khi bạn bắt đầu công việc mới và muốn tách nó khỏi bản checkout chính.
- ✓Khi bạn muốn kiểm tra một pull request hoặc commit trong thư mục riêng.
- ✓Khi một nhánh đã được checkout ở đâu đó, skill báo vị trí đó thay vì tạo một bản sao thứ hai.
Liên kết skill
https://github.com/EveryInc/compound-engineering-plugin/blob/main/skills/ce-worktree/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thiết lập một không gian làm việc riêng cho tính năng này để thư mục chính của tôi không bị động đến.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill trước tiên kiểm tra công việc đã được tách biệt chưa, rồi dùng công cụ worktree tích hợp hoặc git thuần để tạo không gian mới, và báo đường dẫn cùng nhánh của nó.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Worktree Isolation
Ensure the current work happens in an isolated workspace, without disturbing the user's main checkout. Most coding harnesses now create a worktree by default at session start, so the common case is that isolation already exists.
Done when: the caller is working in an isolated tree — existing or newly created — and its path and branch have been reported, or a blocker has been reported instead.
Order of operations: detect existing isolation -> prefer a native worktree tool -> fall back to plain git. Never create a worktree the harness cannot see.
Two modes, set by the caller's need:
- New work (default). No ref named — create a fresh branch from a base (trunk). This is what
ce-workandce-code-reviewuse when the user picks the worktree option. - Isolate an existing ref. The caller names a PR head, branch, or commit — attach the worktree to that ref instead of creating a new branch. A branch can be checked out in only one worktree at a time. If the named ref is already checked out anywhere (most commonly as the primary checkout's current branch), do not create a second worktree — report that it is already checked out at
<path>and let the caller act (work there in place; or, only if a clean separate tree is essential, create a detached worktree at the same commit).
Step 0: Detect existing isolation
Compare the resolved absolute git dir against the resolved absolute common git dir. Git mixes absolute and relative forms depending on the current directory (from a subdirectory of a normal checkout, --git-dir comes back absolute while --git-common-dir may be relative), so a raw string compare yields a false "already isolated":
git rev-parse --absolute-git-dir # absolute git dir for this worktree
(cd "$(git rev-parse --git-common-dir)" && pwd -P) # absolute shared (common) git dir
Equal -> normal checkout; continue to Step 1.
Different -> a linked worktree or a submodule. Distinguish with git rev-parse --show-superproject-working-tree:
- Non-empty -> submodule; treat it as a normal checkout and continue to Step 1.
- Empty -> already isolated. Report the worktree path (
git rev-parse --show-toplevel) and current branch, then work in place — a worktree-from-worktree lands in the wrong tree and is invisible to the harness that made the current one. In isolate-an-existing-ref mode, check that ref out here (unless it is already current) rather than nesting a worktree.
Step 1: Prefer the harness's native worktree tool
If the harness provides a native worktree primitive — for example an EnterWorktree / WorktreeCreate tool, a /worktree command, or a --worktree flag — use it and stop. Native tools place, track, and clean up the worktree so the harness can manage it. A behind-the-back git worktree add creates phantom state the harness cannot see, navigate to, or clean up.
Step 2: Git fallback
Only when there is no native tool and Step 0 found no existing isolation.
- Run from the repo root:
cd "$(git rev-parse --show-toplevel)". The paths below are repo-root-relative, but the skill runs from the user's current directory — without this,.worktrees/<branch>and the.gitignoreedit land in a subdirectory (e.g.src/.worktrees/...). - Choose a meaningful branch name from the work description (e.g.
feat/login,fix/email-validation) — never an opaque auto-generated one. Base: origin's default branch, elsemain. - Ensure
.worktrees/is gitignored before creating anything:git check-ignore -q .worktrees/— with the trailing slash, so an existing directory-only.worktrees/rule is honored even before the directory exists (without the slash the probe misses it and dirties a correctly-configured repo). Not ignored -> add a.worktrees/line to.gitignore. - Refresh the base with
git fetch origin <from-branch>. This is non-fatal — nooriginremote, a differently-named remote, or a local-only branch is not an abort; continue with the local ref. - Create the worktree, per mode:
- New work:
git worktree add -b <branch-name> .worktrees/<branch-name> origin/<from-branch>(use the local<from-branch>ref iforigin/<from-branch>does not exist). - Existing branch or tag:
git worktree add .worktrees/<slug> <target-ref>. - PR: check it out on a local branch —
git fetch origin pull/<n>/head:pr-<n>then `
- New work:
Câu hỏi thường gặp
Việc này có thay đổi bản checkout chính của tôi không?
Không. Nó được thiết kế để không làm xáo trộn bản checkout chính của bạn.
Nó có gắn worktree vào một nhánh pull request có sẵn không?
Có. Nó có thể gắn worktree vào một nhánh, pull request hoặc commit có sẵn.
Nếu nhánh đang được dùng thì sao?
Nó cho bạn biết nhánh đang được checkout ở đâu, và bạn quyết định bước tiếp theo.
Chi tiết
Mô tả gốc của tác giả
Set up isolated git worktrees — create a new branch for fresh work, or attach a worktree to an existing branch, PR, or commit. Use when starting isolated work or isolating an existing ref.
Độ phổ biến
- Sao GitHub
- 26k
- Vị trí xếp hạng
- #10052
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
ce-babysit-pr
26kGiúp agent của bạn theo dõi pull request GitHub đang mở, xử lý bình luận review, kiểm tra lỗi và nhánh cũ để nó tiến tới khi được merge.
ce-bakeoff
26kGiúp agent của bạn xây dựng nhiều giải pháp cạnh tranh cho một vấn đề, so sánh chúng và kết hợp các phần mạnh nhất thành một cách tiếp cận được đề xuất.
ce-brainstorm
26kGiúp agent của bạn biến một ý tưởng mơ hồ thành tập yêu cầu rõ ràng, vừa đủ quy mô, trước khi bắt đầu làm, qua một cuộc trò chuyện có hướng dẫn ngắn.
ce-code-review
26kGiúp agent của bạn review một thay đổi mã hoặc pull request để tìm lỗi, hồi quy, thiếu kiểm thử và vi phạm tiêu chuẩn, rồi báo cáo rõ ràng.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.