GI

git_merge_workflow

Prevents push conflicts in a dual-remote setup by enforcing a strict PR-based merge workflow for the `main` branch.

Install

mkdir -p .claude/skills/git-merge-workflow && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15365" && unzip -o skill.zip -d .claude/skills/git-merge-workflow && rm skill.zip

Installs to .claude/skills/git-merge-workflow

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Safe merge workflow for two-remote setup (origin + github) to avoid force-pushes
80 charsno explicit “when” trigger
Intermediate

Key capabilities

  • Sync `main` and `dev` branches across two remotes
  • Avoid force-pushes in a two-remote setup
  • Create pull requests from `dev` to `main` on GitHub
  • Resolve merge conflicts during pull operations
  • Keep local mirror (`origin`) in sync
  • Merge `main` back into `dev` to prevent future conflicts

How it works

This skill provides a step-by-step workflow for safely merging the `dev` branch into `main` across two Git remotes, ensuring compliance with GitHub branch protection rules and avoiding force-pushes.

Inputs & outputs

You give it
a local Git repository with `origin` and `github` remotes and `dev`/`main` branches
You get back
synchronized `main` and `dev` branches across both remotes, with changes merged via PR

When to use git_merge_workflow

  • Merging dev into main
  • Syncing remotes
  • Avoiding git merge conflicts

About this skill

Git Merge Workflow (Two-Remote Setup)

Problem

This project uses two independent Git remotes:

  • origin → local mirror (always push)
  • github → GitHub with Actions and Dependabot (always push)

GitHub's main receives Dependabot PR auto-merges independently. If a local feature branch is merged into main without pulling from both remotes first, push to one remote will be rejected, requiring a rebase that invalidates commit hashes on the other remote → force-push needed.

GitHub Branch Protection on main

GitHub enforces branch protection rules on main:

  • No direct pushesgit push github main is rejected with GH013: Repository rule violations
  • Changes must go through a Pull Request (from dev or a feature branch)
  • 4 required status checks must pass before merge
  • Only merge commits allowed (no squash, no rebase)

Consequence: Never run git push github main directly. Always create a PR.

Required Workflow: Merge dev into main

Use this workflow ONLY when you intend to release dev → main via PR. Do NOT use this workflow just to sync with Dependabot — use the Daily Workflow instead.

Always execute these steps in order:

# 0. Verify all refs are in sync before starting.
#    Run the for-each-ref command below. If any SHA mismatches exist between
#    local, origin/main, and github/main, pull from both remotes and resolve
#    conflicts before proceeding.
git for-each-ref --format='%(refname:short) %(objectname:short)' refs/heads/main refs/heads/dev refs/remotes/origin/main refs/remotes/origin/dev refs/remotes/github/main refs/remotes/github/dev

# 1. Switch to main and sync from BOTH remotes
git checkout main
git pull origin main
git pull github main    # picks up any Dependabot auto-merges
# If either pull results in a merge conflict: stop, resolve conflicts manually,
# commit the merge, then re-run step 0 to confirm sync before continuing.

# 2. Push the source branch (dev) to github if not already up to date
git push github dev

# 3. Create a PR on GitHub: dev → main
# Use mcp_github_mcp_se_create_pull_request or the GitHub UI.
# If PR creation fails because a PR already exists for dev → main, locate and use the existing PR.
# If PR creation fails because dev and main are already identical (no diff), skip steps 3–4 and go to step 5.
#
# If CI checks fail:
#   (a) Do NOT merge the PR.
#   (b) Push a fix commit to dev on github (git push github dev).
#   (c) The existing open PR will pick up the new commit automatically.
#   (d) Wait for CI to pass again before merging.
#
# Merge the PR using the GitHub UI or mcp_github_mcp_se_merge_pull_request.
# Do NOT proceed to step 4 until `git ls-remote github refs/heads/main` shows the new merge commit.
# Wait for user confirmation or poll until the merge commit appears.

# 4. After GitHub merges the PR: sync main, then merge back into dev
git pull github main
git push origin main    # keep local mirror in sync
# If git push origin main is rejected: run `git pull origin main` to inspect the divergence.
# If origin/main has commits not on github/main, merge origin/main into local main, then re-push.
# Do not force-push.

# 5. Merge main back into dev to stay in sync
# main may have Dependabot auto-merge commits that dev doesn't have yet.
# Without this step, the next PR from dev → main will include unrelated Dependabot commits.
git checkout dev
git pull github main    # fetch github/main; git pull merges it into current branch (dev)
git push origin dev
git push github dev

When This Applies

  • Merging dev or any feature branch into main
  • After a CI workflow is green and ready for release
  • Before any release tag

For feature branches other than dev: substitute the feature branch name wherever dev appears in the Required Workflow. Step 5 (merge main back into dev) should also be performed on the feature branch to keep it current. The Daily Workflow applies to dev only.

When This Does NOT Apply

  • Pushing feature branches to github (no branch protection there)
  • Pushing anything to origin (local mirror — no branch protection)

Why Both Pulls Are Necessary

Dependabot auto-merges PRs into GitHub's main (since 2026-05-12). These commits don't exist on origin or locally. Without git pull github main, the local main diverges from GitHub's main, and merging dev into main will be rejected or cause conflicts.

Daily Workflow (Dependabot sync)

Use this workflow ONLY at the start of a session or after a Dependabot merge, when no PR to main is being created. If you intend to merge dev → main via PR, use the Required Workflow above instead.

Dependabot merges minor/patch updates automatically into main every Monday (or whenever a PR passes CI). To stay in sync:

# At the start of each working session:
git checkout dev
git pull github dev      # picks up any direct changes to dev on GitHub
git fetch github main    # fetch github/main without merging into dev
git merge github/main    # explicitly merge fetched github/main into dev
git push origin dev
git push github dev

# After your own work:
git push origin dev
git push github dev

This ensures dev never falls behind main and PRs into main are always conflict-free.

Check SHA on all repos (local, origin, github) before merging to confirm they are in sync. If you see a mismatch, do not merge until you have pulled from both remotes and resolved any conflicts.

git for-each-ref --format='%(refname:short) %(objectname:short)' refs/heads/main refs/heads/dev refs/remotes/origin/main refs/remotes/origin/dev refs/remotes/github/main refs/remotes/github/dev

When not to use it

  • When pushing feature branches to `github` (no branch protection there)
  • When pushing anything to `origin` (local mirror , no branch protection)
  • When the goal is only to sync with Dependabot without creating a PR to main

Limitations

  • The workflow is for a two-remote setup (origin + github)
  • The workflow requires changes to go through a Pull Request for `main`
  • The workflow assumes GitHub enforces branch protection rules on `main`

How it compares

This skill offers a specific, ordered workflow for a two-remote Git setup with GitHub branch protection, explicitly addressing Dependabot auto-merges and preventing force-pushes, unlike generic Git merge instructions.

Compared to similar skills

git_merge_workflow side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
git_merge_workflow (this skill)02moReviewIntermediate
github-workflow-automation112moReviewAdvanced
testing-workflow169moReviewIntermediate
github-actions-templates74moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

Search skills

Search the agent skills registry