Skip to content
Shell
997 B
Raw Blame
#!/bin/bash
# Auto Git Workflow: Automatically manages git branches for features

USER_MESSAGE="$1"

# Check if we're in a git repo
if ! git rev-parse --git-dir > /dev/null 2>&1; then
  exit 0
fi

# Detect if this is a new feature request (look for keywords)
if echo "$USER_MESSAGE" | grep -iE "(add|create|build|new feature|implement)" > /dev/null; then
  CURRENT_BRANCH=$(git branch --show-current)

  # Only auto-create branch if on main/master
  if [[ "$CURRENT_BRANCH" == "main" ]] || [[ "$CURRENT_BRANCH" == "master" ]]; then
    # Extract feature name from message (simple heuristic)
    FEATURE_NAME=$(echo "$USER_MESSAGE" | head -1 | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | cut -c1-50 | sed 's/-*$//')
    BRANCH_NAME="feature/$FEATURE_NAME"

    echo "🌿 Creating feature branch: $BRANCH_NAME"
    echo "💡 Claude will work here and create a PR when done"

    # Signal to Claude to create the branch
    echo "CLAUDE_ACTION: create_branch:$BRANCH_NAME"
  fi
fi

exit 0