Automatically create git worktrees from GitHub issue webhooks. Each issue gets its own isolated workspace!
BranchCraft is a lightweight Python utility that integrates with GitHub webhooks to automatically create git worktrees whenever a new issue is opened. This allows developers to work on multiple issues simultaneously without the hassle of switching branches in their main repository.
- 🎯 Automatic Worktree Creation: Creates a new git worktree for each GitHub issue
- 🏷️ Smart Branch Naming: Generates branches like
123-fix-login-bugfrom issue numbers and titles - 📁 Organized Structure: Keeps worktrees in a clean
issues/{org/repo}/{branch}structure - 🚀 Zero Dependencies: Uses only Python standard library
- 🔄 Webhook Integration: Works seamlessly with GitHub webhook events
- Clone this repository:
git clone https://github.com/clidecoder/branchcraft.git
cd branchcraft- Make the script executable:
chmod +x branchcraft.pyRun BranchCraft with a GitHub webhook payload:
python branchcraft.py '{"action":"opened","issue":{"number":123,"title":"Fix login bug"},"repository":{"full_name":"myorg/myapp","name":"myapp"}}'This will:
- Clone the repository (if not already present)
- Create a new branch:
123-fix-login-bug - Create a worktree at:
issues/myorg/myapp/123-fix-login-bug/
- Set up a webhook in your GitHub repository settings
- Point it to your webhook handler endpoint
- Configure it to trigger on "Issues" events
- Have your webhook handler execute BranchCraft with the payload
Example webhook handler (Flask):
from flask import Flask, request
import subprocess
import json
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def handle_webhook():
payload = request.json
if payload.get('action') == 'opened' and 'issue' in payload:
subprocess.run(['python', 'branchcraft.py', json.dumps(payload)])
return '', 200your-workspace/
├── myorg/
│ └── myapp/ # Main repository
└── issues/
└── myorg/
└── myapp/
├── 123-fix-login-bug/ # Worktree for issue #123
├── 124-add-user-profile/ # Worktree for issue #124
└── 125-update-docs/ # Worktree for issue #125
- Webhook Reception: GitHub sends a webhook when an issue is opened
- Branch Creation: BranchCraft creates a branch name from the issue number and title
- Repository Setup: Clones the repository if needed
- Worktree Creation: Creates a new git worktree for the issue branch
- Ready to Code: Developer can immediately start working in the isolated worktree
- Python 3.6+
- Git command-line tool
- Access to the repository you want to create worktrees for
- Parallel Development: Work on multiple issues without branch switching
- Clean Workspace: Each issue has its own isolated environment
- Fast Context Switching: Jump between issues instantly
- Automatic Setup: No manual branch creation or cloning needed
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
Created with ❤️ for developers who juggle multiple issues