agentleFS
Cogni-AI-OUCogni-AI-OU/cogni-ai-agent-skills/git-merge/SKILL.md

git-merge

Skill4 starsChanged 7 months agoMITView on GitHub

Guide and safety rules for performing git merges, ensuring no conflict markers and no duplicate lines are present. You MUST load this skill before performing a git merge.

  • Deletes or force-pushes

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. 0 are common, 15 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 15

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    When explicitly integrating a feature branch into a target branch (like main).

    line 17
  2. Distinctive:

    When syncing upstream changes into your current branch to resolve an out-of-date PR.

    line 18
  3. Distinctive:

    Before running a test suite that requires the absolute latest code from the base branch.

    line 19
  4. Distinctive:

    When a linear history is strictly enforced by the repository policies (use git rebase instead).

    line 23
  5. Distinctive:

    If you just need to apply a single, isolated commit (use git cherry-pick).

    line 25
  6. Distinctive:

    Pre-Flight Check: Ensure the working directory is perfectly clean (git status) and the repository is not shallowed.

    line 35
  7. Distinctive:

    Inspect Conflicts: If conflicts occur, resolve them explicitly file by file.

    line 38
  8. Very specific:

    Clean File Verification: Check every resolved file to ensure absolutely no Git conflict markers (<<<<<<<, =======, >>>>>>>) remain.

    line 39
  9. Distinctive:

    Clean State: Always begin a merge from a clean working tree.

    line 47
  10. Distinctive:

    Ensure the repository is not shallow.

    line 49
  11. Very specific:

    Non-Interactive: Prefer non-interactive commands.

    line 52
  12. Very specific:

    Use tools like sort | uniq -d on specific regions or manually inspect imports and declarations.

    line 71
  13. Very specific:

    Accidental Bad Merge: If the merge went wrong and you haven't pushed, use git merge --abort (if in progress) or git reset --hard HEAD~1 (if …

    line 79
  14. Very specific:

    Merge Stuck in Conflict: Use git status to identify unmerged paths.

    line 81
  15. Distinctive:

    Process Stuck: If git process hangs, ensure no interactive prompt was launched.

    line 83
  16. Distinctive:

    Avoid using interactive merge tools that stall the agent process.

    line 87
  17. Distinctive:

    Do not commit if git status shows unmerged files.

    line 88
  18. Distinctive:

    Do not push a merge without first verifying the application builds and tests pass locally.

    line 89
  19. Distinctive:

    Never blindly git add . without checking the contents of resolved files.

    line 90
  20. Very specific:

    Never leave <<<<<<< HEAD or >>>>>>> markers in the codebase.

    line 91
  21. Distinctive:

    All conflict resolution must be done via text editing tools or by fully rewriting the file content.

    line 96

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: git-merge

<!-- markdownlint-disable MD013 MD023 MD031 MD032 -->

Execute safe and verified git merges. This skill enforces pre-merge checks, explicit conflict resolution, and strict post-merge validation to prevent duplicate lines or lingering conflict markers.

When to Use

  • When explicitly integrating a feature branch into a target branch (like main).
  • When syncing upstream changes into your current branch to resolve an out-of-date PR.
  • Before running a test suite that requires the absolute latest code from the base branch.

When Not to Use

  • When a linear history is strictly enforced by the repository policies (use git rebase instead).
  • For extracting a specific subdirectory into a new repository (use git-filter-branch or filter-repo).
  • If you just need to apply a single, isolated commit (use git cherry-pick).

Common Pitfalls

  • Shallow History: Attempting a complex merge in a shallow-cloned repository (fetch-depth: 1), resulting in weird conflicts or missing base commits.
  • Blind Commits: Running git commit -am "merge" without actually inspecting the conflicted files, leaving <<<<<<< HEAD markers in the production codebase.
  • Duplicate Imports: Resolving a conflict by keeping "both" sides without realizing that this duplicated an import statement or variable declaration, breaking the build.

Core Process

  1. Pre-Flight Check: Ensure the working directory is perfectly clean (git status) and the repository is not shallowed. Otherwise you need to unshallow it.
  2. Execute Merge: Perform the merge (e.g., git merge <branch> --no-edit --no-ff).
  3. Inspect Conflicts: If conflicts occur, resolve them explicitly file by file.
  4. Clean File Verification: Check every resolved file to ensure absolutely no Git conflict markers (<<<<<<<, =======, >>>>>>>) remain.
  5. Deduplication Check: Review the resolved sections to ensure no logical duplicates (e.g., duplicate imports, repeated variable declarations, or duplicate lines) were introduced.
  6. Commit and Validate: Finalize the merge commit, run local tests, and check the log.

Core Principles

  • Clean State: Always begin a merge from a clean working tree. If there are uncommitted changes, stash or commit them first.
  • Deep History: Ensure the repository is not shallow. Merging in a shallow repository can lead to unexpected results or failures.
  • No Duplicate Lines: Merging can often result in duplicated logic if both branches added similar lines. You must manually verify that no duplicate imports, definitions, or statements exist post-merge.
  • Non-Interactive: Prefer non-interactive commands. Do not launch git mergetool or GUI merge tools, and use --no-edit or GIT_EDITOR=true to avoid editor prompts during merge and commit steps.
  • Zero Conflict Markers: A merge must never be committed if standard Git conflict markers remain in the file.

Commands / Usage Patterns

  • Check Working Directory: git status --short
  • Check for Shallow Repository: git rev-parse --is-shallow-repository (must return false before merging to ensure full history is available)
  • Review Differences Before Merge: git diff HEAD..<target-branch> --name-only
  • Perform Merge: git merge <target-branch> --no-ff --no-edit -m "Merge <target-branch> into HEAD"
  • Find Conflict Markers: grep -rnE "<<<<<<<|=======|>>>>>>>" . (Must return no output before finalizing the merge).
  • Find Duplicate Lines (heuristic): Use tools like sort | uniq -d on specific regions or manually inspect imports and declarations.
  • Finalize Merge: git commit --no-edit (if conflicts were manually resolved and added).
  • Unshallow Repository: git fetch origin master --unshallow || git fetch origin master

Diagnostics and Troubleshooting

  • Accidental Bad Merge: If the merge went wrong and you haven't pushed, use git merge --abort (if in progress) or git reset --hard HEAD~1 (if already committed).
  • Merge Stuck in Conflict: Use git status to identify unmerged paths. Edit them, run git add <file>, and then git commit --no-edit.
  • Process Stuck: If git process hangs, ensure no interactive prompt was launched. Abort and rerun non-interactively.

What to Avoid

  • Avoid using interactive merge tools that stall the agent process.
  • Do not commit if git status shows unmerged files.
  • Do not push a merge without first verifying the application builds and tests pass locally.
  • Never blindly git add . without checking the contents of resolved files.
  • Never leave <<<<<<< HEAD or >>>>>>> markers in the codebase.

Limitations

  • The agent cannot use graphical merge conflict tools (e.g., kdiff3, meld). All conflict resolution must be done via text editing tools or by fully rewriting the file content.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.