Git Repository Code Extraction
Intelligently extract meaningful code from Git repositories. Automatically filters out noise like build artifacts, dependencies, and generated files while preserving the important source code you need for analysis or LLM processing.
Smart Filtering
Automatically excludes build artifacts, node_modules, and generated files
Gitignore Respect
Honors .gitignore files by default for accurate extraction
Flexible Output
Export as JSON, plain text, or preserve directory structure
Workflow Overview
The Git extraction tool operates in four distinct phases to intelligently extract code:
1. Source Acquisition
Determines if working with a remote URL or local directory. For remote repos, performs a shallow clone.
2. File Filtering
Applies intelligent filtering rules to identify important files, respecting .gitignore and user patterns.
3. Content Aggregation
Reads filtered files into memory, detecting and skipping binary files automatically.
4. Output & Cleanup
Formats content as requested (JSON, text, or directory) and cleans up temporary files.
Command Structure
Basic Syntax
BASH001omnivore git <source> [flags]
The <source> parameter can be:
- A remote repository URL:
https://github.com/user/repo.git - A local directory path:
.or../my-project
Filtering Options
Include Patterns
Use --include to switch to whitelist mode, where only files matching specified patterns are kept:
BASH001# Include only Rust source files and Cargo.toml002omnivore git . --include "src/**/*.rs,Cargo.toml" --json003004# Include only JavaScript and TypeScript files005omnivore git https://github.com/user/repo.git \006 --include "**/*.js,**/*.ts,**/*.jsx,**/*.tsx" \007 --output ./js-code
Exclude Patterns
Use --exclude to blacklist specific files or patterns:
BASH001# Exclude test files and logs002omnivore git . --exclude "*.log,**/*test*,**/*spec*" --txt003004# Exclude specific directories005omnivore git . --exclude "target/,dist/,build/" --output ./clean-code
Gitignore Handling
BASH001# Respect .gitignore (default behavior)002omnivore git . --json003004# Ignore .gitignore files005omnivore git . --no-gitignore --output ./all-files
Output Formats
JSON Output
Perfect for programmatic processing and integration with other tools:
BASH001# Output as JSON to stdout002omnivore git . --json003004# Save JSON to file005omnivore git . --json > codebase.json006007# Pipe to jq for processing008omnivore git . --json | jq '.[] | select(.path | contains("src"))'
JSON structure:
JSON001[002 {003 "path": "src/main.rs",004 "content": "fn main() {\n println!(\"Hello, world!\");\n}"005 },006 {007 "path": "Cargo.toml",008 "content": "[package]\nname = \"omnivore\"\nversion = \"0.1.0\""009 }010]
Text Output
Ideal for feeding into LLMs or text processing pipelines:
BASH001# Output as plain text with separators002omnivore git . --txt003004# Pipe to an LLM005omnivore git . --txt | llm "Analyze this codebase"006007# Save to file008omnivore git . --txt > codebase.txt
Text format example:
TEXT001---002File: src/main.rs003---004fn main() {005 println!("Hello, world!");006}007---008File: Cargo.toml009---010[package]011name = "omnivore"012version = "0.1.0"
Directory Output
Preserves the original file structure in a new directory:
BASH001# Extract to directory (default if no format specified)002omnivore git https://github.com/user/repo.git --output ./extracted003004# Local repository extraction005omnivore git . --output ../clean-copy006007# With filtering008omnivore git . \009 --include "src/**/*" \010 --output ./src-only
Advanced Features
Binary File Handling
BASH001# Skip binary files (default)002omnivore git . --json003004# Include binary files (only works with --output)005omnivore git . --allow-binary --output ./with-binaries006007# Binary files are automatically detected and skipped in JSON/TXT modes
Clone Depth Control
BASH001# Shallow clone (default: depth 1)002omnivore git https://github.com/user/repo.git --output ./code003004# Specific clone depth005omnivore git https://github.com/user/repo.git --depth 10 --output ./code006007# Full clone (all history)008omnivore git https://github.com/user/repo.git --depth 0 --output ./code
File Size Limits
BASH001# Set maximum file size (10MB)002omnivore git . --max-file-size 10485760 --json003004# Skip large generated files (1MB limit)005omnivore git . --max-file-size 1048576 --txt
Temporary Clone Management
BASH001# Keep temporary clone for debugging002omnivore git https://github.com/user/repo.git \003 --keep \004 --output ./code005006# Temporary clones are deleted by default
Filtering Logic
Multi-Layer Filtering Funnel
Files pass through multiple filtering layers to determine inclusion:
1. System Excludes
Always ignores: .git/, .svn/, .hg/
2. .gitignore Processing
Respects all .gitignore files (unless --no-gitignore)
3. User Excludes
Applies --exclude patterns
4. Binary Detection
Skips binary files (unless --allow-binary)
5. User Includes
If specified, only keeps files matching --include patterns
Common Use Cases
Prepare Codebase for LLM Analysis
BASH001# Extract only source code as text002omnivore git . \003 --exclude "**/*test*,**/*spec*,docs/" \004 --txt | llm "Review this code for security issues"005006# Create JSON for structured analysis007omnivore git . \008 --include "src/**/*.py,*.py" \009 --json | python analyze_code.py
Repository Migration
BASH001# Clone and clean a repository002omnivore git https://github.com/old/repo.git \003 --exclude "node_modules/,dist/,*.log" \004 --output ./clean-repo005006# Extract only source files007omnivore git . \008 --include "src/**/*,package.json,README.md" \009 --output ../migration/
Code Documentation
BASH001# Extract code for documentation002omnivore git . \003 --include "**/*.rs" \004 --exclude "target/,tests/" \005 --json | jq -r '.[].content' > all_code.txt006007# Generate file listing008omnivore git . --json | jq -r '.[].path' > file_list.txt
Multi-Repository Analysis
BASH001#!/bin/bash002# analyze_repos.sh003004repos=(005 "https://github.com/user/repo1.git"006 "https://github.com/user/repo2.git"007 "https://github.com/user/repo3.git"008)009010for repo in "${repos[@]}"; do011 name=$(basename "$repo" .git)012 omnivore git "$repo" \013 --include "**/*.go" \014 --json > "${name}.json"015done016017# Combine all JSON files018jq -s 'add' *.json > combined.json
Error Handling
Authentication
The tool relies on system-wide Git credentials. If authentication fails:
BASH001# For SSH URLs, ensure SSH keys are configured002ssh-add ~/.ssh/id_rsa003004# For HTTPS URLs, configure credential helper005git config --global credential.helper cache006007# Error message example:008# "Authentication failed. Ensure your Git credentials are configured correctly."
Invalid Repository
BASH001# Local directory must be a Git repository002omnivore git /path/to/non-git-dir --json003# Error: '/path/to/non-git-dir' is not a Git repository004005# Verify repository006ls -la .git/ # Should exist for local repos
Conflicting Flags
BASH001# Cannot use multiple output formats002omnivore git . --json --txt003# Error: Cannot use --json and --txt together004005# Cannot use format flags with --output006omnivore git . --json --output ./dir007# Error: Cannot use --json with --output
Empty Results
BASH001# If filtering results in no files002omnivore git . --include "*.xyz" --json003# Output: []004005omnivore git . --include "*.xyz" --txt006# Output: (empty)007008omnivore git . --include "*.xyz" --output ./empty009# Creates empty directory
Performance Considerations
Large Repositories
- Use shallow clones (
--depth 1) for faster operations - Set file size limits to skip large generated files
- Use specific include patterns to reduce processing
BASH001# Optimize for large repos002omnivore git https://github.com/large/repo.git \003 --depth 1 \004 --include "src/**/*.java" \005 --max-file-size 1048576 \006 --output ./extracted
Memory Management
For very large codebases, consider processing in chunks:
BASH001# Process different parts separately002omnivore git . --include "frontend/**/*" --output ./frontend-code003omnivore git . --include "backend/**/*" --output ./backend-code004omnivore git . --include "shared/**/*" --output ./shared-code
Security Considerations
- Symbolic links are not followed to prevent security risks
- Binary files are detected and excluded by default
- File paths are sanitized to prevent directory traversal
- Temporary clones are created in secure system temp directories
- Git credentials are never stored or logged by the tool
Best Practices
- Always use shallow clones for remote repositories unless full history is needed
- Set appropriate file size limits to avoid memory issues
- Use include patterns for specific file types when possible
- Test patterns on small repositories first
- Respect .gitignore files unless you have a specific reason not to
- Use JSON output for programmatic processing
- Use text output for LLM consumption
- Keep binary detection enabled for text/JSON outputs
Troubleshooting
Common Issues and Solutions
Network Timeouts
BASH001# Increase Git timeout002git config --global http.postBuffer 524288000003git config --global http.timeout 600004005# Use SSH instead of HTTPS006omnivore git [email protected]:user/repo.git --output ./code
Character Encoding Issues
BASH001# Files with non-UTF8 encoding are skipped002# Warning: Skipped file.txt (invalid UTF-8 encoding)003004# Convert files to UTF-8 first if needed005iconv -f ISO-8859-1 -t UTF-8 input.txt > output.txt
Large File Warnings
BASH001# Set appropriate size limits002omnivore git . --max-file-size 5242880 --json # 5MB limit003004# Or exclude large file patterns005omnivore git . --exclude "*.sqlite,*.db,*.zip" --json
Integration Examples
GitHub Actions Workflow
YAML001name: Code Analysis002on: [push, pull_request]003004jobs:005 analyze:006 runs-on: ubuntu-latest007 steps:008 - uses: actions/checkout@v2009010 - name: Install Omnivore011 run: |012 curl -sSfL https://raw.githubusercontent.com/Pranav-Karra-3301/omnivore/master/install.sh | sh013014 - name: Extract Code015 run: |016 omnivore git . \017 --include "src/**/*.rs" \018 --json > codebase.json019020 - name: Analyze021 run: |022 python analyze.py codebase.json
Pre-commit Hook
BASH001#!/bin/sh002# .git/hooks/pre-commit003004# Extract and check code size005size=$(omnivore git . --json | wc -c)006max_size=10485760 # 10MB007008if [ $size -gt $max_size ]; then009 echo "Error: Codebase too large ($size bytes)"010 exit 1011fi012013echo "Codebase size: $size bytes"