搜索

PythonReactSEOPDF
GitHub Skill

using-git-worktrees

You are an expert user of git worktrees. You interact with git worktrees to implement tasks.

tmitchel2☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Using Git Worktrees Skill

This skill guides interaction with git worktrees, you will you the git cli for working with worktrees.

Reference help for 'git worktree' command

git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]
                        [-b <new-branch>] <path> [<commit-ish>]
   or: git worktree list [-v | --porcelain [-z]]
   or: git worktree lock [--reason <string>] <worktree>
   or: git worktree move <worktree> <new-path>
   or: git worktree prune [-n] [-v] [--expire <expire>]
   or: git worktree remove [-f] <worktree>
   or: git worktree repair [<path>...]
   or: git worktree unlock <worktree>

IMPORTANT Using A Git Worktree with Submodules

There are some important considerations when using a git worktree with a project that has submodules:

How They Work Together

  1. Submodules are repository-wide: Submodules are tracked in the main repository's .git/modules/ directory, which is shared across all worktrees. This means all worktrees see the same submodule repositories.
  2. Each worktree can check out different submodule commits: While the submodule repositories themselves are shared, each worktree can have the submodule checked out at different commits, just like any other file in the repository.
  3. Initialization required per worktree: When you create a new worktree, you'll need to run git submodule update --init in that worktree to populate the submodule directories.

Common Workflow

  1. Create a new worktree (e.g. git worktree add ../my-worktree branch-name)
  2. Navigate to the new worktree (e.g. cd ../my-worktree)
  3. Initialize and update submodules (e.g. git submodule update --init --recursive)

Potential Issues

  • Detached HEAD states: Submodules in worktrees can sometimes end up in detached HEAD states, requiring manual checkout
  • Nested worktrees: You cannot create a worktree inside a submodule's directory
  • Update carefully: When updating submodules, be aware that changes affect the shared submodule repository.

Using Git Worktrees Workflow

  1. Create the worktree.
  2. Navigate to the worktree folder.
  3. Check for the usage of git submodules by checking for a .gitmodules file.
  4. Initialize and update submodules.

Using Git Worktrees Notes

  • Executing scripts in a git worktree may require one "cd" before calling the script and then another "cd" after to return to the original directory. E.g. cd /private/tmp/claude/graphlessdb-issue-164 && git pull origin main && cd /users/blah/github/graphlessdb. Put another way you will need to cd into the worktree folder before each execution of a script and then you will need to cd back to the original folder to reset the pwd back to what it was before.
  • Check for existing branches before creating one. Use git worktree add <path> <existing-branch> if branch exists, not -b flag
  • Create new git worktrees under the folder /tmp/claude/.

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!