Skip to main content

Git simulation and visualization engine - dry run dangerous Git commands with visual feedback before executing

Project description

GitSim - Git Simulation & Visualization Engine

Dry-run dangerous Git commands with visual feedback before executing them.

GitSim is a sophisticated Git simulation tool that lets you preview the exact outcome of complex Git operationsโ€”including conflict prediction, safety analysis, and visual before/after graphsโ€”without touching your repository. Think of it as a "flight simulator" for Git commands.

CI PyPI version Downloads Python 3.11+ License: MIT Code style: ruff


๐ŸŽฏ Why GitSim?

The Problem: Git's most powerful commands (rebase, merge, reset, cherry-pick) are also its most dangerous. One wrong move can rewrite history, lose work, or create messy conflicts.

The Solution: GitSim simulates these operations in a safe, read-only environment, showing you:

  • โœ… Exact outcome with before/after commit graphs
  • โœ… Predicted conflicts with file-level details and certainty levels
  • โœ… Safety ratings (LOW/MEDIUM/HIGH/CRITICAL danger levels)
  • โœ… Recovery steps if something goes wrong
  • โœ… Educational explanations of how Git commands work internally

Perfect for:

  • ๐ŸŽ“ Learning Git - See exactly how operations transform your repository
  • ๐Ÿ’ผ Complex merges - Preview conflicts before starting a multi-hour merge
  • ๐Ÿ”ง History rewriting - Safely plan rebases on shared branches
  • ๐Ÿ‘ฅ Team education - Teach Git workflows with visual demonstrations
  • ๐Ÿš€ CI/CD safety - Validate Git operations in automation scripts

โšก Quick Start

# Install from PyPI (v1.0.1)
pipx install gitsimulator

# All three commands work identically:
gitsim rebase main
git-sim rebase main
gitsimulator rebase main

# Preview a merge with conflict detection
gitsim merge feature-branch

# Learn how Git commands work
gitsim explain rebase

# Save repository state for experiments
gitsim snapshot create before-rebase

๐ŸŽจ Features

๐Ÿ›ก๏ธ Core Simulation Commands

gitsim rebase

  • Simulate rebasing branches
  • Predict conflicts per commit
  • Show new commit SHAs
  • Warn about force-push requirements
  • Detailed safety analysis

gitsim merge

  • Preview three-way merges
  • Detect fast-forward opportunities
  • Show merge commit creation
  • File-by-file conflict prediction
  • Merge base analysis

gitsim reset

  • Test --soft, --mixed, --hard modes
  • Preview unreachable commits
  • Working directory impact
  • Staged changes analysis
  • Recovery instructions

gitsim cherry-pick

  • Simulate picking commits
  • Multi-commit support
  • Step-by-step conflict detection
  • Short/full SHA resolution
  • New commit preview

๐Ÿ“Š Analysis & Visualization

  • Conflict Detection Engine

    • CERTAIN conflicts: Same lines modified (90%+ accuracy)
    • LIKELY conflicts: Nearby changes within 3 lines
    • POSSIBLE conflicts: Same file modifications
    • File-level granularity with line ranges
  • Safety Analysis System

    • Danger Levels: LOW โ†’ MEDIUM โ†’ HIGH โ†’ CRITICAL
    • Reversibility: Can operation be undone?
    • Force-push Required: Will remote history diverge?
    • Data Loss Risk: Commits becoming unreachable?
    • Recovery Suggestions: Step-by-step undo instructions
  • Visual Commit Graphs

    • ASCII art graphs (matches git log --graph)
    • Before/After comparisons side-by-side
    • Branch topology visualization
    • Highlighted commits and changes
    • Color-coded output with Rich library

๐ŸŽ“ Educational Features

gitsim explain <command> - Interactive learning mode:

  • ๐Ÿ“– Plain-English explanations of Git internals
  • ๐Ÿ” Step-by-step algorithm breakdowns
  • โš ๏ธ Risk assessment and common pitfalls
  • ๐Ÿ’ก Best practices and safety tips
  • ๐Ÿ”„ Alternative approaches
  • ๐Ÿ”— Related commands and references

Supported explanations: rebase, merge, reset, cherry-pick, stash, tag

๐Ÿ”ง Advanced Tools

  • Snapshot System - Save/restore repository states

    • Named snapshots with metadata
    • HEAD position tracking
    • Branch state preservation
    • Timestamped history
    • Quick rollback for experiments
  • Unified Simulator - gitsim sim "any-git-command"

    • Natural syntax parsing
    • All operations supported
    • Consistent output format
  • Plugin Architecture

    • Hook plugins (pre/post/override simulation)
    • Custom simulators
    • Output formatters
    • Entry point discovery
  • Interactive TUI - gitsim tui

    • Textual-powered interface
    • Real-time command preview
    • Headless mode for scripting

๐Ÿ“ฆ Installation

From PyPI (Recommended)

# Install with pipx (v1.0.1)
pipx install gitsimulator

# Or with pip
pip install gitsimulator

Note: All three commands work identically: gitsim, git-sim, and gitsimulator

From Source

git clone https://github.com/egekaya1/GitSimulator.git
cd GitSimulator
pip install -e ".[dev]"

Requirements

  • Python: 3.11, 3.12, or 3.13
  • OS: Linux, macOS, Windows
  • Dependencies:
    • dulwich (Pure Python Git implementation)
    • rich (Terminal formatting)
    • typer (CLI framework)
    • textual (TUI, optional)

๐Ÿ’ป Usage Examples

Rebase Simulation

$ gitsim rebase main

Simulating: git rebase main

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Rebase Summary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚   Source branch       feature       โ”‚
โ”‚   Target branch       main          โ”‚
โ”‚   Merge base          abc1234       โ”‚
โ”‚   Commits to replay   3             โ”‚
โ”‚   Predicted conflicts 1             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Safety Analysis โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚   Danger Level           ๐Ÿ”ด HIGH     โ”‚
โ”‚   Reversible             Yes        โ”‚
โ”‚   Force Push Required    Yes        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Before Rebase:
* abc1234 (HEAD -> feature) Add authentication
* def5678 Update config
| * 123abcd (main) Fix security bug
|/
* 789xyz0 Initial commit

After Rebase (Simulated):
* new1234' (HEAD -> feature) Add authentication
* new5678' Update config
* 123abcd (main) Fix security bug
* 789xyz0 Initial commit

โš ๏ธ  Found 1 CERTAIN conflict in config.py (lines 45-52)

Recovery: git reflog to restore, git reset --hard ORIG_HEAD

Merge with Conflict Prediction

$ gitsim merge feature-auth

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Merge Summary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Source branch   feature-auth       โ”‚
โ”‚  Target branch   main               โ”‚
โ”‚  Merge type      Three-way          โ”‚
โ”‚  Files changed   8                  โ”‚
โ”‚  Conflicts       2 CERTAIN          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

          Potential Conflicts          
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Severity   โ”ƒ File       โ”ƒ Details   โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ CERTAIN    โ”‚ auth.py    โ”‚ Lines     โ”‚
โ”‚            โ”‚            โ”‚ 23-45     โ”‚
โ”‚ CERTAIN    โ”‚ config.yml โ”‚ Lines     โ”‚
โ”‚            โ”‚            โ”‚ 12-18     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Educational Mode

$ gitsim explain rebase

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ git rebase โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Rebase re-applies commits from one  โ”‚
โ”‚ branch onto another, creating new   โ”‚
โ”‚ commits with different SHAs.        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

How it works:
  1. Find merge base (common ancestor)
  2. Save commits to replay
  3. Reset HEAD to target branch
  4. Apply each commit sequentially
  5. Generate new SHAs for all commits

What changes:
  โ€ข All rebased commits get new SHAs
  โ€ข Commit timestamps updated
  โ€ข Linear history (no merge commits)
  โ€ข Parent references rewritten

Risks:
  โš ๏ธ HISTORY REWRITE - Collaborators affected
  โš ๏ธ FORCE PUSH REQUIRED - Remote diverges
  โš ๏ธ CONFLICTS - May repeat for each commit
  
Safety tips:
  โœ“ Never rebase public/shared branches
  โœ“ Create backup: git branch backup-mybranch
  โœ“ Use git reflog to recover mistakes

Alternatives:
  โ€ข git merge - Preserves history
  โ€ข git cherry-pick - Pick specific commits

๐Ÿ—๏ธ Architecture & Technical Details

System Design

GitSim follows a clean, modular architecture with strict separation of concerns:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    CLI Layer (Typer)                    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Commands โ”‚ Options  โ”‚ Parsing  โ”‚ User Interface   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Simulation Dispatcher                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚ โ€ข Command routing                                โ”‚   โ”‚
โ”‚  โ”‚ โ€ข Plugin hook execution (pre/override/post)      โ”‚   โ”‚
โ”‚  โ”‚ โ€ข Result validation                              โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ–ผ              โ–ผ              โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ Rebase  โ”‚    โ”‚  Merge  โ”‚    โ”‚  Reset  โ”‚
    โ”‚Simulatorโ”‚    โ”‚Simulatorโ”‚    โ”‚Simulatorโ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚              โ”‚              โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Core Services                         โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚ Repository   โ”‚ Diff         โ”‚ Conflict         โ”‚     โ”‚
โ”‚  โ”‚ (Dulwich)    โ”‚ Analyzer     โ”‚ Detector         โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 Git Repository (.git/)                  โ”‚
โ”‚              (Read-only access via Dulwich)             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

1. Repository Layer (core/repository.py)

Pure Python Git access via Dulwich - no git binary required:

class Repository:
    """Read-only Git repository wrapper."""
    
    def get_commit(self, ref_or_sha: str) -> CommitInfo:
        """Resolve refs/SHAs to commits (supports short SHAs)."""
    
    def walk_commits(self, include: list[str], exclude: list[str] | None) -> Iterator[CommitInfo]:
        """Topological commit traversal."""
    
    def get_commit_changes(self, sha: str) -> list[FileChange]:
        """Extract file changes from commit."""
    
    def build_graph(self, refs: list[str], max_commits: int) -> CommitGraph:
        """Build DAG representation."""

Key features:

  • Short SHA resolution (7+ characters with ambiguity detection)
  • Relative ref support (HEAD~2, main^)
  • Topological sorting for graph display
  • Lazy loading for performance

2. Simulation Engines (simulation/)

Each simulator implements BaseSimulator[T] protocol:

class BaseSimulator(Protocol[T]):
    def validate(self) -> tuple[list[str], list[str]]:
        """Pre-flight checks โ†’ (errors, warnings)."""
    
    def simulate(self) -> T:
        """Execute simulation โ†’ typed result."""

Rebase Simulator (simulation/rebase.py):

  • Algorithm: Find merge base โ†’ collect commits โ†’ replay onto target
  • Conflict detection: Compare each commit's changes against target
  • SHA generation: Deterministic fake SHAs for visualization
  • Step tracking: Detailed operation steps with conflicts

Merge Simulator (simulation/merge.py):

  • Three-way merge analysis (base vs ours vs theirs)
  • Fast-forward detection
  • Merge commit synthesis
  • Conflict accumulation across all files

Reset Simulator (simulation/reset.py):

  • Mode handling: SOFT (staged only), MIXED (unstaged), HARD (discarded)
  • Detached commit tracking
  • Working directory simulation
  • Reflog recovery instructions

Cherry-Pick Simulator (simulation/cherry_pick.py):

  • Sequential commit application
  • Cumulative conflict detection
  • Parent relationship preservation
  • Merge commit warnings

3. Conflict Detection (simulation/conflict_detector.py)

Sophisticated heuristics engine with three certainty levels:

class ConflictDetector:
    def detect_conflicts(
        self,
        our_changes: list[FileChange],
        their_changes: list[FileChange],
    ) -> list[ConflictInfo]:
        """Multi-level conflict analysis."""

Detection Strategy:

  1. CERTAIN (90%+ accuracy):

    • Same file, overlapping line ranges
    • Both sides modify identical lines
    • Binary file conflicts
  2. LIKELY (70%+ accuracy):

    • Changes within 3 lines of each other
    • Same function/class modifications
    • High churn areas
  3. POSSIBLE (50%+ accuracy):

    • Same file modified
    • Different sections
    • Semantic conflicts (imports, etc.)

Algorithm:

for each file changed in OURS:
    if file changed in THEIRS:
        parse diff hunks
        for each hunk_ours:
            for each hunk_theirs:
                if hunks_overlap(hunk_ours, hunk_theirs):
                    โ†’ CERTAIN conflict
                elif hunks_nearby(hunk_ours, hunk_theirs, threshold=3):
                    โ†’ LIKELY conflict
                else:
                    โ†’ POSSIBLE conflict

4. Data Models (core/models.py)

Type-safe data classes (Python 3.11+ dataclasses):

@dataclass
class SimulationResult:
    """Unified result type for all simulations."""
    operation_type: OperationType
    success: bool
    before_graph: CommitGraph
    after_graph: CommitGraph
    conflicts: list[ConflictInfo]
    warnings: list[str]
    safety_info: SafetyInfo
    changed_files: list[FileChange]

@dataclass
class CommitGraph:
    """DAG representation with branch topology."""
    commits: dict[str, CommitInfo]
    edges: list[tuple[str, str]]  # (child, parent)
    branch_tips: dict[str, str]    # branch โ†’ SHA
    head_sha: str
    
@dataclass
class ConflictInfo:
    """Detailed conflict information."""
    severity: ConflictSeverity  # CERTAIN | LIKELY | POSSIBLE
    file_path: str
    description: str
    our_lines: tuple[int, int] | None
    their_lines: tuple[int, int] | None

5. Plugin System (plugins/)

Extensible architecture with three plugin types:

class HookPlugin(Plugin):
    """Intercept simulation lifecycle."""
    
    def pre_simulate(self, repo, command, **kwargs) -> dict:
        """Modify inputs before simulation."""
    
    def override_simulation(self, repo, command, **kwargs) -> SimulationResult | None:
        """Replace simulation entirely (or None to continue)."""
    
    def post_simulate(self, repo, command, result) -> SimulationResult:
        """Modify results after simulation."""

class SimulatorPlugin(Plugin):
    """Add new simulation commands."""
    
    def supports(self, command: str) -> bool:
        """Can this plugin handle the command?"""
    
    def simulate(self, **kwargs) -> SimulationResult:
        """Execute custom simulation."""

class FormatterPlugin(Plugin):
    """Custom output formatting."""
    
    def format_result(self, result: SimulationResult) -> str:
        """Render simulation result."""

Discovery: Entry points in pyproject.toml:

[project.entry-points."git_sim.plugins"]
my_plugin = "my_package.plugin:MyPlugin"

Performance Optimizations

  1. Lazy Graph Building: Only load commits needed for visualization
  2. Diff Caching: Memoize expensive diff operations
  3. Short SHA Indexing: Stop at first unique match
  4. Parallel-Safe: Pure functional core, no shared state
  5. Memory Efficient: Stream commits vs loading entire history

Testing Strategy

135 tests covering:

  • Unit tests: Each component in isolation
  • Integration tests: End-to-end command flows
  • Property tests: Invariant checking (graphs are DAGs, etc.)
  • Fixture-based: Multiple repo states (linear, branched, merge commits)
pytest --cov=git_sim --cov-report=html
# Current: 95%+ coverage

๐Ÿ” Security & Safety

Read-Only Guarantee

GitSim never writes to your repository:

  • Uses Dulwich's read-only API
  • No git subprocess calls that modify state
  • Simulations run entirely in memory
  • Snapshot system uses separate .git/git-sim-snapshots/ directory

Plugin Safety

  • Plugins run in same process (trust required)
  • Hook plugins can modify simulation behavior
  • Override plugins can replace entire simulations
  • See SECURITY.md for plugin security considerations

๐Ÿ“Š Comparison with Alternatives

Feature GitSim git log --graph GitKraken lazygit tig
Simulation โœ… Full โŒ No โŒ No โŒ No โŒ No
Conflict Prediction โœ… 3 levels โŒ No โš ๏ธ Basic โŒ No โŒ No
Safety Analysis โœ… Yes โŒ No โŒ No โŒ No โŒ No
Educational Mode โœ… Yes โŒ No โŒ No โŒ No โŒ No
Terminal UI โœ… Yes โœ… Yes โŒ GUI only โœ… Yes โœ… Yes
No Git Binary โœ… Pure Python โŒ Requires Git โŒ Requires Git โŒ Requires Git โŒ Requires Git
Snapshot System โœ… Yes โŒ No โš ๏ธ Via GUI โŒ No โŒ No
Plugin System โœ… Yes โŒ No โœ… Yes โŒ No โŒ No
SSH-Friendly โœ… Yes โœ… Yes โŒ No โœ… Yes โœ… Yes
Price โœ… Free โœ… Free ๐Ÿ’ฐ Paid โœ… Free โœ… Free

GitSim's Unique Value: Only tool combining safe simulation + conflict prediction + education + beautiful CLI.


๐Ÿ› ๏ธ Development

Setup

git clone https://github.com/egekaya1/GitSimulator.git
cd GitSimulator
python -m venv .venv
source .venv/bin/activate  # or `.venv\Scripts\activate` on Windows
pip install -e ".[dev]"

Testing

# Run all tests
pytest

# With coverage
pytest --cov=git_sim --cov-report=html

# Specific test file
pytest tests/test_rebase.py

# Watch mode
pytest-watch

Code Quality

# Type checking
mypy src/git_sim --ignore-missing-imports

# Linting
ruff check src/git_sim tests

# Formatting
ruff format src/git_sim tests

# All checks (what CI runs)
ruff check src/git_sim tests && \
ruff format --check src/git_sim tests && \
mypy src/git_sim --ignore-missing-imports && \
pytest --cov=git_sim

Project Structure

GitSimulator/
โ”œโ”€โ”€ src/git_sim/           # Source code
โ”‚   โ”œโ”€โ”€ cli/               # Command-line interface
โ”‚   โ”‚   โ”œโ”€โ”€ main.py        # Typer app entry point
โ”‚   โ”‚   โ”œโ”€โ”€ commands/      # Command implementations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ rebase.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ merge.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”‚   โ””โ”€โ”€ formatters/    # Output rendering
โ”‚   โ”‚       โ”œโ”€โ”€ graph.py   # Commit graph ASCII art
โ”‚   โ”‚       โ”œโ”€โ”€ conflict.py # Conflict tables
โ”‚   โ”‚       โ””โ”€โ”€ diff.py    # Diff visualization
โ”‚   โ”œโ”€โ”€ core/              # Core business logic
โ”‚   โ”‚   โ”œโ”€โ”€ repository.py  # Dulwich wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ models.py      # Data classes
โ”‚   โ”‚   โ”œโ”€โ”€ diff_analyzer.py # Diff parsing
โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py  # Custom errors
โ”‚   โ”œโ”€โ”€ simulation/        # Simulation engines
โ”‚   โ”‚   โ”œโ”€โ”€ base.py        # Abstract base
โ”‚   โ”‚   โ”œโ”€โ”€ dispatcher.py  # Command routing
โ”‚   โ”‚   โ”œโ”€โ”€ rebase.py      # Rebase logic
โ”‚   โ”‚   โ”œโ”€โ”€ merge.py       # Merge logic
โ”‚   โ”‚   โ”œโ”€โ”€ reset.py       # Reset logic
โ”‚   โ”‚   โ”œโ”€โ”€ cherry_pick.py # Cherry-pick logic
โ”‚   โ”‚   โ”œโ”€โ”€ conflict_detector.py # Conflict heuristics
โ”‚   โ”‚   โ””โ”€โ”€ explain.py     # Educational content
โ”‚   โ”œโ”€โ”€ tui/               # Terminal UI
โ”‚   โ”‚   โ””โ”€โ”€ app.py         # Textual application
โ”‚   โ”œโ”€โ”€ plugins/           # Plugin system
โ”‚   โ”‚   โ”œโ”€โ”€ base.py        # Plugin protocols
โ”‚   โ”‚   โ””โ”€โ”€ loader.py      # Discovery & loading
โ”‚   โ””โ”€โ”€ snapshot.py        # State management
โ”œโ”€โ”€ tests/                 # Test suite (135 tests)
โ”‚   โ”œโ”€โ”€ conftest.py        # Pytest fixtures
โ”‚   โ”œโ”€โ”€ test_rebase.py
โ”‚   โ”œโ”€โ”€ test_merge.py
โ”‚   โ”œโ”€โ”€ test_conflict_detection.py
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ .github/workflows/     # CI/CD
โ”‚   โ””โ”€โ”€ ci.yml             # Automated testing & publishing
โ”œโ”€โ”€ pyproject.toml         # Package metadata
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ CHANGELOG.md           # Version history
โ”œโ”€โ”€ CONTRIBUTING.md        # Development guide
โ”œโ”€โ”€ SECURITY.md            # Security policy
โ””โ”€โ”€ LICENSE.md             # MIT license

๐Ÿ“œ License

MIT License - see LICENSE.md


๐Ÿ™ Acknowledgments

Built with these excellent libraries:

  • Dulwich - Pure Python Git implementation
  • Rich - Beautiful terminal formatting
  • Typer - CLI framework
  • Textual - TUI framework

๐Ÿ“ž Support & Contributing


โญ Star us on GitHub if GitSim helps you!

Installation

# From PyPI (v1.0.1)
pipx install gitsimulator

# Or with pip
pip install gitsimulator

# For development
git clone https://github.com/egekaya1/GitSim.git
cd GitSim
pip install -e .

Note: All three commands work identically: gitsim, git-sim, and gitsimulator

Usage

Simulate a Rebase

git-sim rebase main                     # Simulate rebasing onto main
git-sim rebase main --source feature    # Specify source branch
git-sim rebase main --verbose           # Show detailed conflict info
git-sim rebase main --execute           # Execute after confirmation

Simulate a Merge

git-sim merge feature                   # Simulate merging feature
git-sim merge feature --no-ff           # Force merge commit

Simulate a Reset

git-sim reset HEAD~2 --soft             # Keep changes staged
git-sim reset HEAD~2                    # Unstage changes (mixed)
git-sim reset HEAD~2 --hard             # Discard all changes

Simulate Cherry-Pick

git-sim cherry-pick abc123              # Pick single commit
git-sim cherry-pick abc123 def456       # Pick multiple commits

Unified Simulation Command

git-sim sim "rebase main"
git-sim sim "merge feature"
git-sim sim "reset --hard HEAD~2"
git-sim sim "cherry-pick abc123"

Educational Features

git-sim explain rebase                  # Learn how rebase works
git-sim explain merge                   # Learn how merge works
git-sim explain reset                   # Learn about reset modes
git-sim explain cherry-pick             # Learn about cherry-pick

Snapshot System

git-sim snapshot create "before-rebase" # Save current state
git-sim snapshot list                   # List all snapshots
git-sim snapshot restore "before-rebase"# Restore to snapshot
git-sim snapshot delete "before-rebase" # Delete snapshot

Other Commands

git-sim status                          # Show repository status
git-sim log                             # Show commit graph
git-sim diff HEAD~1                     # Show commit diff

Example Output

Simulating: git rebase main

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Rebase Summary                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Source branch    feature                โ”‚
โ”‚ Target branch    main                   โ”‚
โ”‚ Merge base       abc1234                โ”‚
โ”‚ Commits to replay 3                     โ”‚
โ”‚ Predicted conflicts 1                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Safety Analysis                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Danger Level     ๐Ÿ”ด HIGH                โ”‚
โ”‚ Reversible       Yes                    โ”‚
โ”‚ Force Push Required Yes                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Before Rebase:
* abc1234 (HEAD -> feature) Add new feature
* def5678 Update config
| * 123abcd (main) Fix bug
|/
* 789xyz0 Initial commit

After Rebase (Simulated):
* new1234 (HEAD -> feature) Add new feature
* new5678 Update config
* 123abcd (main) Fix bug
* 789xyz0 Initial commit

โš ๏ธ Found 1 potential conflict(s)

CERTAIN: Lines 10-15 in 'config.py' modified differently on both sides

Development

pip install -e ".[dev]"                 # Install dev dependencies
pytest                                  # Run tests
pytest --cov=git_sim                    # Run with coverage
mypy src/git_sim --ignore-missing-imports  # Type check
ruff check src/git_sim                  # Lint
ruff format --check src/git_sim         # Format check

Project Structure

git-sim/
โ”œโ”€โ”€ src/git_sim/
โ”‚   โ”œโ”€โ”€ cli/                    # CLI commands and formatters
โ”‚   โ”‚   โ”œโ”€โ”€ main.py             # Typer app entry point
โ”‚   โ”‚   โ”œโ”€โ”€ commands/           # Command implementations
โ”‚   โ”‚   โ””โ”€โ”€ formatters/         # Output formatters (graph, diff, conflict)
โ”‚   โ”œโ”€โ”€ core/                   # Core components
โ”‚   โ”‚   โ”œโ”€โ”€ models.py           # Data models (SimulationResult, CommitGraph, etc.)
โ”‚   โ”‚   โ”œโ”€โ”€ repository.py       # Git repository wrapper (Dulwich)
โ”‚   โ”‚   โ”œโ”€โ”€ diff_analyzer.py    # Diff parsing and analysis
โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py       # Custom exceptions
โ”‚   โ”œโ”€โ”€ simulation/             # Simulation engines
โ”‚   โ”‚   โ”œโ”€โ”€ dispatcher.py       # Unified command dispatcher
โ”‚   โ”‚   โ”œโ”€โ”€ base.py             # Abstract base simulator
โ”‚   โ”‚   โ”œโ”€โ”€ rebase.py           # Rebase simulation
โ”‚   โ”‚   โ”œโ”€โ”€ merge.py            # Merge simulation
โ”‚   โ”‚   โ”œโ”€โ”€ reset.py            # Reset simulation
โ”‚   โ”‚   โ”œโ”€โ”€ cherry_pick.py      # Cherry-pick simulation
โ”‚   โ”‚   โ”œโ”€โ”€ conflict_detector.py# Conflict detection heuristics
โ”‚   โ”‚   โ””โ”€โ”€ explain.py          # Educational explanations
โ”‚   โ”œโ”€โ”€ tui/                    # Terminal UI (Textual)
โ”‚   โ”‚   โ””โ”€โ”€ app.py              # Interactive TUI application
โ”‚   โ”œโ”€โ”€ plugins/                # Plugin system
โ”‚   โ”‚   โ”œโ”€โ”€ base.py             # Plugin base classes
โ”‚   โ”‚   โ””โ”€โ”€ loader.py           # Plugin discovery and loading
โ”‚   โ””โ”€โ”€ snapshot.py             # Snapshot/restore functionality
โ”œโ”€โ”€ tests/                      # Test suite
โ””โ”€โ”€ .github/workflows/          # CI/CD pipeline

Key Concepts

SimulationResult

All simulators return a unified SimulationResult:

from git_sim.simulation import simulate

result = simulate("rebase", onto="main")
print(result.operation_type)    # OperationType.REBASE
print(result.has_conflicts)     # True/False
print(result.safety_info)       # Safety analysis

Safety Levels

Level Description
LOW Safe, easily reversible
MEDIUM Potentially destructive but recoverable
HIGH History rewrite, force-push risk
CRITICAL Data loss risk

Interactive TUI

git-sim tui                             # Launch interactive terminal UI

Plugin System

git-sim plugin list                     # List available plugins
git-sim plugin new my-plugin            # Generate plugin template
git-sim plugin new my-hook --type hook  # Generate hook plugin
git-sim plugin load my-plugin           # Load a plugin

Roadmap

  • Rebase simulation
  • Merge simulation
  • Reset simulation
  • Cherry-pick simulation
  • Unified dispatcher
  • Safety analysis
  • Educational mode (explain)
  • Snapshot/restore
  • Interactive TUI mode (Textual)
  • Plugin system

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitsimulator-1.0.9.tar.gz (86.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitsimulator-1.0.9-py3-none-any.whl (74.6 kB view details)

Uploaded Python 3

File details

Details for the file gitsimulator-1.0.9.tar.gz.

File metadata

  • Download URL: gitsimulator-1.0.9.tar.gz
  • Upload date:
  • Size: 86.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitsimulator-1.0.9.tar.gz
Algorithm Hash digest
SHA256 77e70a694d0b4df882825a9e863376ad2522261a87ed965d31b9d6d74f418053
MD5 011fbd2df714908a301f5090d3a2fa79
BLAKE2b-256 27b3452c0476efe76463501a8ca6f9b54142e5cec2c5081248e95b46dd353991

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitsimulator-1.0.9.tar.gz:

Publisher: ci.yml on egekaya1/GitSimulator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gitsimulator-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: gitsimulator-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 74.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitsimulator-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ca78833475c453428f45e822efacc7fc7fa9100d8b43d38b69712b1e02ff06fd
MD5 553c3dd6adc33937530c326650c6f944
BLAKE2b-256 8168a7e2cd42b08630490f868508131db09c95bb2eeabdf46e14c1c148057b32

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitsimulator-1.0.9-py3-none-any.whl:

Publisher: ci.yml on egekaya1/GitSimulator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page