Split files while preserving git blame history.
git-split restructures source files by creating temporary git branches, performing git mv operations, then merging — so every line retains its original authorship and commit history.
pip install git-splitOr for development:
git clone <repo-url>
cd git-split
pip install -e ".[dev]"Add SPLIT:EXTRACT / SPLIT:ENDBLOCK markers as comments in your source file:
# Code that stays in the original file
def helper():
pass
# SPLIT:EXTRACT:models.py
class User:
name: str
class Post:
title: str
# SPLIT:ENDBLOCK
def main():
passThen run:
git-split source.pygit-split "source.py:10-20:new_file.py"-p, --preview Show preview of changes
-n, --dry-run Perform a dry run without making any changes
-y, --accept-all Accept all changes without confirmation
-m, --message Custom commit message
git-split includes an MCP server for use with LLMs:
pip install "git-split[mcp]"
git-split-mcp- detect_blocks — Scan a file for SPLIT markers
- preview_split — Preview how a file would be split
- execute_split — Execute the split (requires
confirm=True)
git-split://syntax/markers— Documentation of the marker format
- Parse the file and identify blocks to extract (via markers or line ranges)
- For each target file, create a temporary branch and
git mvthe source - Octopus-merge all temporary branches
- Rename temp copies back to original filenames
- Overwrite each file with only its designated lines
- Merge back to the original branch with
--no-ff - Clean up temporary branches
This script was created by Pavel Gurevich.
MIT