Compare rendered Helm chart output between the current branch and another branch.
# Compare against auto-detected main/master branch
helm_template_diff.sh mychart/ --values prod-values.yaml
# Compare against specific branch
helm_template_diff.sh mychart/ --values prod-values.yaml --against origin/main
# Compare with multiple values files
helm_template_diff.sh charts/api/ -f values.yaml -f overrides.yaml --against feature/update
# Show help
helm_template_diff.sh --help$ helm_template_diff.sh ./mychart --values values.yaml --against origin/main
Auto-detected comparison branch: origin/main
Rendering chart on current branch...
Creating temporary worktree for origin/main...
Rendering chart on origin/main...
Diff (current branch vs origin/main):
diff --git a/tmp/other.yaml b/tmp/current.yaml
index 1234567..abcdefg 100644
--- a/tmp/other.yaml
+++ b/tmp/current.yaml
@@ -10,7 +10,7 @@ metadata:
name: myapp
spec:
replicas: 3
- image: myapp:v1.0.0
+ image: myapp:v1.1.0
ports:
- containerPort: 8080bash3.x or later - Script uses bash-specific features. The#!/bin/bashshebang ensures it runs in bash even if your shell is zsh.git- For branch management and diff operationshelm- For rendering Helm charts- Must be run from within a git repository
- Parses command-line arguments to extract the
--againstbranch (or auto-detects origin/main or origin/master) - Validates that you're in a git repository and the target branch exists
- Renders the Helm chart on your current branch (including all staged and unstaged changes)
- Creates a temporary git worktree for the comparison branch
- Removes files larger than 5MB from the worktree to prevent helm errors
- Renders the Helm chart in the worktree (clean state of the other branch)
- Uses
git diff --no-indexto compare the two rendered outputs - Cleans up temporary files and worktree
Automatic Fallback: If helm template fails on either branch (e.g., due to file size limits, template errors, or missing dependencies), the script automatically falls back to comparing the raw chart source files using git diff. This ensures you can still see what changed even when rendering isn't possible.
The use of git worktree ensures your current working directory remains untouched during the comparison. Large files (>5MB) are automatically removed from the worktree to prevent helm from encountering its file size limit.
0- Success (diff generated, which may be empty or show differences)1- Error (missing dependencies, git errors, or helm template failures)