Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "magic-merge-commit",
"owner": {
"name": "koppor"
},
"metadata": {
"description": "Marketplace hosting the magic-merge-commit Claude Code plugin."
},
"plugins": [
{
"name": "magic-merge-commit",
"source": "./",
"description": "Fix Git merge conflicts caused by a squash-merged base branch."
}
]
}
11 changes: 11 additions & 0 deletions .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "magic-merge-commit",
"description": "Fix a Git merge conflict caused by a squash-merged base branch. Wraps the jbang-based magic-merge-commit tool.",
"version": "1.0.0",
"author": {
"name": "Oliver Kopp"
},
"homepage": "https://github.com/koppor/magic-merge-commit",
"repository": "https://github.com/koppor/magic-merge-commit",
"keywords": ["git", "merge", "squash", "conflict", "pull-request"]
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.idea/

gg.cmd
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,25 @@ You need to be on the branch which is base on the pull request indicated by `<pr

To have `jbang` working, you need to install it. Find information at the [jbang page](https://www.jbang.dev/).

If you don't want to install jbang, place [`gg.cmd`](https://github.com/eirikb/gg#ggcmd) into the root of your git repository and execute as follows:
If you don't want to install jbang, this repository already ships [`gg.cmd`](https://github.com/eirikb/gg#ggcmd) in its root. Execute as follows:

- Linux/macOS: `sh ./gg.cmd jbang do@koppor/magic-merge-commit <pr-number>`
- Windows: `.\gg.cmd jbang do@koppor/magic-merge-commit <pr-number>`

## Use as a Claude Code skill

This repository is also a [Claude Code plugin](https://docs.claude.com/en/docs/claude-code/plugins).
Install it so Claude runs the tool for you when it detects a squash-merge conflict:

```terminal
/plugin marketplace add koppor/magic-merge-commit
/plugin install magic-merge-commit@magic-merge-commit
```

The skill still requires `jbang` (or `gg.cmd`) and a `GITHUB_TOKEN` environment
variable on your machine — it tells Claude *when* and *how* to invoke the tool,
it does not bundle the tool itself.

## Step-by-step description of the scenario

### 1. First pull request is created
Expand Down
Binary file added gg.cmd
Binary file not shown.
53 changes: 53 additions & 0 deletions skills/magic-merge-commit/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: magic-merge-commit
description: Fix a Git merge conflict caused by a squash-merged base branch. Use
when a PR can't merge `main` cleanly because its base branch was squash-merged,
and Git sees the old commits as conflicting with the squashed commit in `main`.
Creates a "magic" merge commit linking the branch to the squashed history.
---

# Magic Merge Commit

Resolves conflicts where a pull request's base branch was squash-merged into
`main`. After the squash-merge, Git no longer connects the branch to its
history, so merging `main` produces spurious conflicts. This skill runs a tool
that creates a merge commit with two parents (`main` + branch tip), wiring the
histories back together so `main` merges cleanly.

## When to use

All of the following are true:

- The user is on a branch that was based on another PR's branch.
- That other PR was **squash-merged** into `main`.
- Merging `main` into the current branch now conflicts.

## Prerequisites (verify before running)

1. `jbang` is on `PATH`. If not, a `gg.cmd` file in the repository root works
as a fallback (see https://github.com/eirikb/gg#ggcmd).
2. The `GITHUB_TOKEN` environment variable is set with read access to the
repository. The tool authenticates via `GitHubBuilder().fromEnvironment()`.
3. The current Git branch is the one based on the squashed PR — not `main`.

If a prerequisite is missing, tell the user how to fix it and stop.

## Run

Ask the user for `<pr-number>` — the number of the PR that was squash-merged
into `main`. Then run:

```
jbang do@koppor/magic-merge-commit <pr-number>
```

Fallback when `jbang` is not installed (`gg.cmd` in repo root):

- Linux/macOS: `sh ./gg.cmd jbang do@koppor/magic-merge-commit <pr-number>`
- Windows: `.\gg.cmd jbang do@koppor/magic-merge-commit <pr-number>`

## After running

The tool creates a merge commit with `main` and the branch tip as parents.
Confirm with `git log --graph --oneline -5` that the magic commit exists, then
the user can merge `main` without conflicts.