Deploy filtered content from one branch to another while preserving git history. Designed for creating distribution branches with build artifacts but without development files.
- Deploy from any branch to any branch with history preservation
- Support for
.distignore,.deployignore, or custom ignore files - Manual exclusions and inclusions (override patterns)
- Optional build scripts (composer, npm, custom commands)
- Automatic composer.json cleanup for distribution
- Customizable commit messages with placeholders
- Secure token management
name: Deploy to Trunk
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: sultann/branch-deploy-action@v1
with:
target-branch: trunkDeploy to trunk without development files:
- uses: sultann/branch-deploy-action@v1
with:
target-branch: trunk
ignore-file: .distignore
script-before: composer install --no-dev --optimize-autoloaderThe action automatically cleans composer.json by removing .extra, .scripts, .config, .repositories, require-dev, and autoload-dev.
Disable composer cleanup if needed:
composer-cleanup: falseSometimes you want trunk to have .github for workflows, but your .distignore excludes it. Use include-paths to override:
- uses: sultann/branch-deploy-action@v1
with:
target-branch: trunk
ignore-file: .distignore # excludes .github
include-paths: .github # but include it anyway- uses: sultann/branch-deploy-action@v1
with:
target-branch: dist
ignore-file: .npmignore
script-before: |
npm ci
npm run build| Input | Description | Required | Default |
|---|---|---|---|
source-branch |
Branch to deploy from | No | Current branch |
target-branch |
Branch to deploy to | Yes | - |
ignore-file |
Path to ignore file | No | .distignore |
include-paths |
Paths to include (overrides ignore-file) | No | - |
script-before |
Commands to run before deployment | No | - |
composer-cleanup |
Clean composer.json for distribution | No | true |
commit-message |
Commit message template | No | Deploy from {source-branch} ({commit-short-sha}) |
github-token |
GitHub authentication token | No | Auto-detected |
Customize commit messages with placeholders:
{source-branch}- Name of the source branch{commit-sha}- Full commit hash{commit-short-sha}- Abbreviated commit hash
Example:
commit-message: "Release from {source-branch} - {commit-short-sha}"Standard gitignore-style format with negation support:
# .distignore example
.git
.github
node_modules
tests
*.md
!README.md
The action processes patterns in this order:
- Default exclusions (
.git/,node_modules/,deploy-temp/) - Includes from
include-paths(processed FIRST so they override ignore-file) - Patterns from
ignore-file
Key point: include-paths is processed before ignore-file, so you can override exclusions.
- Validates inputs and runs build script (if provided)
- Cleans composer.json (if enabled)
- Builds exclusion list from ignore file + manual paths
- Copies filtered files to temporary directory using rsync
- Initializes git and syncs with remote target branch
- Uses
git reset --softto preserve history - Commits changes and pushes to target branch
The action cleans up temporary files on exit, even on failure.
No changes detected
Check your ignore file - it might exclude everything. Common issue: .distignore has .* which excludes all dotfiles.
Permission errors
Ensure your GitHub token has contents: write permission.
Push rejected
The target branch may have protection rules. Check branch settings or use a different workflow trigger.
The action uses git credential helper with cleanup on exit. Tokens never appear in logs or command output. All inputs are validated before execution.
Test the deployment script locally:
export GITHUB_REPOSITORY="owner/repo"
export GITHUB_TOKEN="your-token"
export TARGET_BRANCH="test-branch"
export IGNORE_FILE=".distignore"
bash deploy.shTo publish this action:
- Create repository at
github.com/sultann/branch-deploy-action - Copy files to repository root
- Tag a release:
git tag -a v1.0.0 -m "Initial release" - Push tags:
git push --tags - Create major version tag:
git tag -a v1 -m "Version 1" && git push origin v1
Users can then reference it:
- uses: sultann/branch-deploy-action@v1MIT License
Sultan Nasir Uddin (sultann)