5.8 KiB
Auto-Merge Setup and Usage Guide
Overview
This repository is configured with automated merge capabilities to streamline the development workflow. When a pull request has the automerge label, GitHub will automatically merge it once all required checks pass.
How Auto-Merge Works
The auto-merge workflow (.github/workflows/enable-automerge.yml) automatically enables GitHub's auto-merge feature for pull requests that:
- Have the
automergelabel - Are not in draft status
- Meet all branch protection requirements
Prerequisites
Repository Settings
Ensure the following settings are configured in GitHub:
-
Enable Auto-Merge Feature
- Go to Settings → General
- Scroll to Pull Requests section
- Check ✓ Allow auto-merge
-
Branch Protection Rules (recommended)
- Go to Settings → Branches
- Add rule for
mainbranch:- ✓ Require pull request reviews before merging (at least 1)
- ✓ Require status checks to pass before merging
- Add required check:
CI / validate-and-package
- Add required check:
- ✓ Require branches to be up to date before merging (optional)
Using Auto-Merge
For Pull Request Authors
-
Create a Pull Request
git checkout -b feature/my-new-feature # Make your changes git add . git commit -m "Add new feature" git push origin feature/my-new-feature -
Add the
automergeLabel- Go to your pull request on GitHub
- Click on Labels in the right sidebar
- Select or create the
automergelabel
-
Wait for Checks to Pass
- The auto-merge workflow will automatically enable GitHub's auto-merge
- Once all required checks pass and reviews are approved, the PR will be merged automatically
- The branch will be deleted after merge (if configured)
For This Specific PR
To enable auto-merge for your pull request:
- Navigate to the pull request in GitHub
- Add the
automergelabel - Ensure all CI checks pass
- Get required approvals (if branch protection requires reviews)
- The PR will automatically merge once all conditions are met
Merge Method
The auto-merge workflow uses squash merge by default. This means:
- All commits in the PR are squashed into a single commit
- The commit message will be the PR title
- The commit description will include all individual commit messages
- Clean, linear commit history on the main branch
Workflow Triggers
The auto-merge workflow runs when:
- A PR is labeled with
automerge - A PR is reopened
- A PR becomes ready for review (no longer draft)
- A PR is synchronized (new commits pushed)
Manual Merge Alternative
If you prefer to merge manually:
- Don't add the
automergelabel - Use GitHub's merge button when ready
- Choose your preferred merge method (squash, merge commit, or rebase)
Troubleshooting
Auto-Merge Not Enabled
If auto-merge doesn't enable automatically:
- Check that the PR has the
automergelabel - Verify the PR is not in draft status
- Review workflow logs in the Actions tab
Auto-Merge Enabled But Not Merging
If auto-merge is enabled but the PR doesn't merge:
- Check if all required status checks are passing
- Verify you have the required number of approvals
- Ensure the branch is up to date (if required)
- Check for merge conflicts
Workflow Permissions
If you see permission errors:
- The workflow requires
contents: writeandpull-requests: writepermissions - These are configured in the workflow file
- Contact repository administrators if issues persist
Security Considerations
- Required Reviews: Always configure branch protection to require reviews for production branches
- Status Checks: Ensure CI checks are required and passing before merge
- CODEOWNERS: Consider adding CODEOWNERS file for critical paths
- Label Permissions: Restrict who can add the
automergelabel in repository settings
Branch Cleanup
After a successful auto-merge:
- GitHub can automatically delete the source branch
- Enable this in Settings → General → Pull Requests
- Check ✓ Automatically delete head branches
Related Workflows
This repository includes other automated workflows:
- CI: Validates code and packages artifacts
- OneDrive Sync: Syncs MT5 files to OneDrive after merge
- Trading News Monitor: Scheduled monitoring of trading news
Examples
Example 1: Feature Branch with Auto-Merge
# Create feature branch
git checkout -b feature/add-new-indicator
git push origin feature/add-new-indicator
# Create PR on GitHub and add 'automerge' label
# Push commits
git commit -m "Add new indicator"
git push
# PR automatically merges when CI passes and reviews are approved
Example 2: Hotfix with Immediate Merge
# Create hotfix branch
git checkout -b hotfix/fix-critical-bug
git push origin hotfix/fix-critical-bug
# Create PR and add 'automerge' label
# Get emergency approval
# CI passes → Auto-merge triggers → Merged!
Best Practices
- Use for routine PRs: Auto-merge works well for well-tested, routine changes
- Review before labeling: Only add
automergeafter reviewing the changes - Monitor CI: Ensure your CI is comprehensive and catches issues
- Test locally: Run tests locally before pushing to catch issues early
- Keep PRs small: Smaller PRs are easier to review and merge safely
Reference
- GitHub Auto-Merge Documentation
- Branch Protection Documentation
- Repository Workflow:
.github/workflows/enable-automerge.yml