Real-time Git merge conflict detection with line-level accuracy.
MergeGuard is a proactive CLI tool that monitors your local workspace and remote repositories. It uses Local AI (Ollama) to analyze potential conflicts in real-time, giving you a risk assessment and resolution strategy before you even run git pull.
Ensure your environment meets the following requirements:
| Requirement | Command to Check | Minimum Version |
|---|---|---|
| Node.js | node -v |
v20.x.x |
| Git | git --version |
Latest |
| Ollama | ollama --version |
Latest |
Prepare the AI Brain:
- Download Ollama from ollama.com.
- Run the following in your terminal:
Note: Ensure Ollama is running in the background.
ollama pull llama3.2
Clone the repository and link the CLI to your system:
# Clone the repository
git clone https://github.com/ghoshvidip26/MergeGuard
cd MergeGuard
# Install dependencies and build
npm install
npm run build
# Link globally so you can use the 'mergeguard' command anywhere
npm linkVerify Installation:
mergeguard --helpTo see MergeGuardβs true power, follow this specific test case:
- Setup: Run mergeguard -w in your test repo.
- Action A (Remote): Go to GitHub.com, edit line 10 of README.md, and commit.
- Action B (Local): Immediately edit line 10 of README.md in your local editor. Do not commit.
- The Result: MergeGuard will detect you are Behind: 1 and have Local Changes. The AI will flag this as HIGH RISK because the line ranges overlap.
| Alert Level | Meaning | Suggested Action |
|---|---|---|
| NONE | No local or remote changes detected. | Keep coding! |
| LOW | Remote changes exist, but in different files. | git pull is safe. |
| MEDIUM | Same file changed, but different lines. | git pull is likely safe (auto-merge). |
| HIGH | Same lines changed on both sides. | Stop. Coordinate before pulling. |
- π Real-time Git monitoring (local + remote)
- π Line-level diff analysis (no coarse file-only checks)
- πΏ Branch-agnostic (works with any feature branch)
- π¨ Conflict risk classification:
- π΄ RISK=HIGH β Same file AND overlapping line ranges.
- π‘ RISK=MEDIUM β Same file, but different line ranges.
- π’ RISK=LOW β Different files entirely.
- βͺ RISK=NONE β No changes or branch is up-to-date.
- π€ AI-assisted analysis (via Ollama) with strict factual guardrails
- π CLI + Socket.IO for live alerts
- β‘ Smart caching to avoid unnecessary recomputation
Navigate to any active Git repository and run:
mergeguard -w- Watches the repository continuously.
- Emits alerts on local changes, remote updates, and conflict risks.
mergeguard -aOr with a custom prompt:
mergeguard -a "Analyze repository safety"- Repository Watcher: Tracks uncommitted local changes and periodically fetches remote updates.
- Data Collection: Uses
git status,git diff, andgit logto collect ground-truth data. - Line-level analysis: Extracts exact line ranges from diff hunks to match local vs remote changes per file.
- AI Analysis: Consumes tool output to explain why a conflict may occur and recommends resolution strategies.
MergeGuard provides a clean, fact-based report based on actual Git hunks and AI analysis: Example-1:
π© ALERT: LOW (Behind: 0, Ahead: 0)
π File Change Details
- src/index.ts
- Change Type: Local
- Status: M
- File Creation Status: Modified
- Exact Line Numbers: Lines 249β277, Lines 328β328, ...
π§ Analysis
Found 3 uncommitted files...
Example-2:
π© ALERT: HIGH (Behind: 1, Ahead: 0)
π File Change Details
- README.md
- Change Type: Remote | Conflict
- Exact Line Numbers: Lines 6β64, Lines 66β66
- File Creation Status: Modified
π§ Analysis
The analysis indicates that there is a HIGH RISK due to overlapping line ranges in the same file. The remote changes have been detected and are causing this risk.
βοΈ Conflict Resolution Strategy
To resolve this conflict, you can choose one of the following strategies:
- Accept Remote: Run 'git pull' and manually resolve conflict markers in affected files.
- Keep Local: During a merge conflict, run 'git checkout --ours <file>' and add the file. Complete the merge with 'git commit'.
- Manual Merge: Run 'git pull' and manually resolve conflict markers in affected files.
Please note that you should coordinate before pulling to avoid any potential issues.
MergeGuard doesnβt just tell you that youβre behind or ahead β
it shows exactly which lines changed on remote vs your local branch.
In this example:
- The remote branch modified
README.mdat:- Lines 103, 106, 111, 113, 118
- The local branch modified the same file at:
- Lines 249β277 and 328
Because both sides changed the same file, MergeGuard correctly reports: π© RISK = MEDIUM and requires a merge decision.
This prevents blind git pull conflicts before they happen.
MergeGuard doesnβt just list changed files β it shows exactly which lines were modified locally and on the remote branch in a single unified view.
This allows you to see before pulling whether you are about to hit a merge conflict.
In this example:
-
The local branch has uncommitted changes in:
src/index.tstools/gitLocal.ts
-
The remote branch has updates in:
README.md
To improve remote detection accuracy and avoid GitHub rate limits, add a Personal Access Token:
- Create a
.envfile in the MergeGuard root directory. - Add your token:
GITHUB_API=github_pat_your_token_here
- Restart the watcher.
The tool uses the GitHub REST API to fetch additional repository metadata (e.g., pull request status, branch protection rules) when a GITHUB_API is provided. This enables more accurate conflict risk assessment and avoids hitting unauthenticated rate limits.
- Set
GITHUB_APIin your.envas described in the Advanced Configuration section. - The token must have
reposcope for private repositories. - If no token is set, the tool falls back to unauthenticated API calls with lower rate limits.
- β
Feature branch vs remote
main - β Open-source contribution model
- β Local commits ahead of remote
- β Remote commits behind local
- β Does NOT auto-merge or modify files
- Node Version: If you see syntax errors, ensure you are on Node 20+.
- Ollama Connection: If analysis hangs, ensure
ollama run llama3.2works independently. - Permissions: You may need
sudo npm linkon some systems.
- TypeScript & Node.js
- simple-git for Git operations
- Socket.IO for live updates
- LangChain & Ollama for AI analysis
- Yargs for CLI management
- Backend / Platform engineers
- Open-source contributors
- Teams with frequent rebases
- Developers tired of surprise merge conflicts