A lightweight GitHub Action that determines the current branch name
and generates a sanitized version safe for artifact names, cache keys, and file paths.
- Detects the current branch name automatically
- Supports both
pushandpull_requestworkflows - Replaces
/and_with- - Exposes both original and sanitized branch names as outputs
- Lightweight and dependency-free
| Output | Description |
|---|---|
branch_name |
Original branch name |
sanitized_branch_name |
Branch name with / and _ replaced by - |
- name: Sanitize branch name
id: branch
uses: onliner/sanitize-branch-name@v1
- name: Print outputs
run: |
echo "Original: ${{ steps.branch.outputs.branch_name }}"
echo "Sanitized: ${{ steps.branch.outputs.sanitized_branch_name }}"| Branch name | Sanitized branch name |
|---|---|
feature/login-ui |
feature-login-ui |
hotfix_bug_123 |
hotfix-bug-123 |
release/v1_2_0 |
release-v1-2-0 |
- Artifact naming (upload-artifact)
- Cache keys (actions/cache)
- Docker tags
- File paths
- Any CI workflow where branch names must be filesystem-safe
Released under the MIT License.