Skip to content

git_worktree has two backends. Pick by how you want to name the target.

Path-addressed (plain git) ​

Needs nothing beyond git itself. Identifies worktrees by filesystem path.

ActionArgumentsNotes
list—Porcelain output, stable for parsing.
addpath, plus branch or detached: trueRefuses to guess: a branch or detached is required.
removepath, optional force
lock / unlockpath, optional lock_reason
pruneoptional expireDrops admin entries for directories that are gone.
repairoptional paths
jsonc
{ "action": "add", "path": "../feature-auth", "branch": "feature/auth" }
{ "action": "list" }

Branch-addressed (git flow worktree) ​

Requires git-flow-next on PATH. Identifies worktrees by branch name, computes the path from the gitflow.worktreePath template, and records which ones it created.

ActionArgumentsNotes
flow_pathbranchPrints the computed path. Creates nothing.
flow_addbranch, optional pathThe branch must already exist. path overrides the computed one.
flow_removebranch, optional forceKeeps the branch. Refuses uncommitted work without force.
flow_list—Tags provenance and detached HEADs.
jsonc
{ "action": "flow_path",  "branch": "feature/user-auth" }
{ "action": "flow_add",   "branch": "feature/user-auth" }
{ "action": "flow_list" }

Path templates ​

Set gitflow.worktreePath to control where worktrees land. The default is a sibling of the repository, so worktrees stay out of your file watcher and search results:

../<repo>-worktrees/<branch>

Variables: , , .

bash
# One directory per topic type, under your home directory
git config gitflow.worktreePath '~/worktrees/{{ topicType }}/{{ branch }}'

# A global default for every repository
git config --global gitflow.worktreePath '~/worktrees/{{ repo }}/{{ branch }}'

Per-call path beats the template without changing it.

Why provenance matters ​

git-flow records the worktrees it creates instead of inferring it from disk. That is what makes cleanup safe: when a branch is finished or deleted, a worktree git-flow created is removed, while one you made by hand with git worktree add is kept and its HEAD detached — so the directory and every uncommitted change in it survive.

git_flow inherits this for topic_action: "finish" and "delete". Use keep_worktree to route a git-flow-created worktree through the detach path, or force_worktree to remove one that has uncommitted changes. Both refuse up front if a merge, rebase, bisect, cherry-pick, or revert is in progress in that worktree.

flow_remove names its target explicitly, so it removes the worktree whatever its origin — it does not try to infer provenance. It never removes the main worktree.

Differences from plain git ​

  • lock_reason is rejected on flow_add: git flow worktree add has no lock flags.
  • flow_remove keeps the branch. Plain git worktree remove also does, but has no --force semantics for uncommitted work beyond git's own refusal.
  • There is no flow_lock, flow_unlock, or flow_repair. Use the path-addressed actions for those.

Released under the MIT License.