Skip to content

Instantly share code, notes, and snippets.

@markus-moser
Last active April 16, 2026 13:37
Show Gist options
  • Select an option

  • Save markus-moser/cc6c3f7fe64924173b55ede600cbd588 to your computer and use it in GitHub Desktop.

Select an option

Save markus-moser/cc6c3f7fe64924173b55ede600cbd588 to your computer and use it in GitHub Desktop.
name: Smart Branch Merge
on:
workflow_dispatch:
inputs:
source_branch:
description: 'Branch to merge FROM (e.g., feature-x)'
required: true
target_branch:
description: 'Branch to merge INTO (e.g., develop)'
required: true
default: 'develop'
jobs:
merge-branches:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "Merge Bot"
git config user.email "bot@github.com"
- name: Perform Smart Merge
run: |
# 1. Switch to the target branch
git checkout ${{ github.event.inputs.target_branch }}
# 2. Attempt the merge, but don't commit yet if it fails
# We use || true so the script doesn't crash on conflicts
git merge origin/${{ github.event.inputs.source_branch }} --no-commit --no-ff || echo "Conflicts detected, attempting auto-resolve..."
# 3. FORCE the build folder to match the TARGET branch (ignores source changes)
# This solves the Rename/Rename and Content conflicts for this folder
git checkout HEAD -- public/build/ || true
git add public/build/
# 4. Check if there are still unmerged files (actual code conflicts)
# "UU" in status means unmerged paths
IF_CONFLICTS=$(git status --porcelain | grep "^UU " || true)
if [ -n "$IF_CONFLICTS" ]; then
echo "❌ ERROR: Merge failed due to REAL code conflicts in these files:"
echo "$IF_CONFLICTS"
git merge --abort
exit 1
else
echo "✅ Build conflicts resolved. Finalizing merge..."
# Check if there's actually anything to commit
if git diff-index --quiet HEAD --; then
echo "Nothing to merge, branches are already synced."
else
git commit -m "chore: merged ${{ github.event.inputs.source_branch }} (Build folder conflicts auto-ignored)"
git push origin ${{ github.event.inputs.target_branch }}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment