# Branch Name Normalization and Validation

## Normalize Branch Name

```bash
normalize_branch_name() {
  echo "$1" | tr '[:upper:]' '[:lower:]' | \
    sed 'y/àâäéèêëïîôùûüçœæ/aaaeeeeiioouucoa/' | \
    sed "s/[ _']/-/g" | sed 's/[^a-z0-9-]//g' | \
    sed 's/--*/-/g' | sed 's/^-//;s/-$//' | cut -c1-50
}

BRANCH_NAME=$(normalize_branch_name "$branch_name")
FULL_BRANCH="${branch_type}/${BRANCH_NAME}"
```

## Check if Branch Already Exists

```bash
# Check if exists
LOCAL_EXISTS=$(git branch --list "$FULL_BRANCH")
REMOTE_EXISTS=$(git branch -r --list "origin/$FULL_BRANCH")

[ -n "$LOCAL_EXISTS" ] || [ -n "$REMOTE_EXISTS" ] && {
  echo "ERROR: Branch '$FULL_BRANCH' already exists"
  # Options: Different name | Checkout existing | Delete and recreate
}
```
