Skip to content

fix: # in branch names breaks Python venv shebang #43

@KazushiMatsuda

Description

@KazushiMatsuda

Problem

When a branch name contains # (e.g., feature/issue#123), the resulting worktree folder name also contains #. This breaks Python virtual environment scripts because the shebang line gets truncated.

Example

Branch: feature/issue#123
Folder: feature-issue#123

The shebang in .venv/bin/python:

#!/path/to/worktrees/feature-issue#123/.venv/bin/python

Shell interprets # as comment start, so it becomes:

#!/path/to/worktrees/feature-issue

This causes "command not found" errors when running any Python tool.

Environment

  • OS: macOS
  • Shell: zsh/bash
  • Git version: 2.x

Proposed Solution

Add # to the character list in sanitize_branch_name() function in lib/core.sh:

-  printf "%s" "$branch" | sed -e 's/[\/\\ :*?"<>|]/-/g' -e 's/^-*//' -e 's/-*$//'
+  printf "%s" "$branch" | sed -e 's/[\/\\ :*?"<>|#]/-/g' -e 's/^-*//' -e 's/-*$//'

This converts feature/issue#123 to feature-issue-123.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions