Skip to content

rerere Git Command Guide

The git rerere (reuse recorded resolution) command records conflict resolutions and automatically applies them when the same conflicts occur again. This is particularly useful for long-lived topic branches that are frequently rebased or merged.

Terminal window
git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
CommandDescription
(no command)Automatically record resolution during conflicts
clearReset metadata if merge resolution is aborted
forget <pathspec>Forget recorded resolutions for specified paths
diffShow diffs for current conflict resolutions
statusShow paths with recorded resolutions
remainingShow paths with conflicts that can be resolved
gcPrune old recorded resolutions
Rerere Workflow:
1. Enable rerere with git config rerere.enabled true
2. During merge conflict, resolve conflicts manually
3. Git automatically records the resolution
4. Next time same conflict occurs, resolution is applied automatically
5. Use git rerere to manage recorded resolutions
Storage Location:
├── Recorded resolutions stored in .git/rr-cache/
├── Each conflict gets SHA-1 based directory
├── Preimage and postimage stored for each resolution
└── Metadata tracks resolution state
Recording Process:
├── Git detects merge conflict
├── Creates preimage (original conflicted state)
├── User resolves conflicts manually
├── Git creates postimage (resolved state)
├── SHA-1 of preimage becomes storage key
└── Resolution stored for future reuse
Automatic Application:
├── Git encounters same conflict again
├── Computes SHA-1 of current conflict state
├── Looks up stored resolution
├── Applies resolution automatically
└── User sees clean merge result
Ideal Use Cases:
├── Long-lived feature branches
├── Frequent rebasing of topic branches
├── Repeated merges with same conflicts
├── Collaborative development with merge conflicts
└── Automated conflict resolution in CI/CD
Not Helpful For:
├── One-time merges
├── Completely different conflicts
├── Conflicts requiring different resolutions
└── Very large repositories (storage overhead)
Terminal window
# Enable rerere globally
git config rerere.enabled true
# Enable for current repository
git config rerere.enabled true
# Check if enabled
git config rerere.enabled
# First time setup with conflict resolution
git merge feature-branch
# Resolve conflicts manually
git add resolved-file.txt
git commit
# Next time same conflict occurs
git merge feature-branch # Resolution applied automatically
Terminal window
# View current status
git rerere status
# Show remaining conflicts that can be resolved
git rerere remaining
# Show diffs of recorded resolutions
git rerere diff
# Forget resolution for specific path
git rerere forget path/to/file.txt
# Clear all recorded resolutions
git rerere clear
Terminal window
# Clean up old resolutions
git rerere gc
# Manual cleanup of rr-cache
find .git/rr-cache -type f -mtime +90 -delete
# Check cache size
du -sh .git/rr-cache/
Terminal window
# Set up rerere for long-lived branch
setup_long_lived_branch() {
local branch_name="$1"
echo "Setting up rerere for long-lived branch: $branch_name"
# Enable rerere
git config rerere.enabled true
# Create and switch to branch
git checkout -b "$branch_name"
# Initial setup complete
echo "Rerere enabled. Conflict resolutions will be recorded automatically."
}
# Usage example
setup_long_lived_branch "feature/complex-ui"
# As you work and rebase frequently:
# 1. Conflicts occur during rebase
# 2. Resolve them once
# 3. Future rebases apply resolutions automatically
Terminal window
# Share rerere resolutions in team
share_rerere_resolutions() {
echo "Setting up shared rerere resolutions"
# Configure shared rerere directory
git config rerere.enabled true
# For team collaboration, consider:
# - Sharing rr-cache via network storage
# - Including resolutions in repository
# - Documenting resolution strategies
echo "Rerere configured for collaborative use"
}
# Team workflow:
# 1. Team enables rerere
# 2. First person resolves conflicts
# 3. Others benefit from recorded resolutions
# 4. Share particularly complex resolutions
Terminal window
# Use rerere in CI/CD for testing
ci_rerere_integration() {
echo "Setting up rerere for CI/CD testing"
# Enable rerere in CI
git config rerere.enabled true
# Pre-populate common resolutions
# (Could be done by copying rr-cache from previous runs)
# Run tests with rerere
if git merge test-branch; then
echo "✓ Merge successful (possibly using rerere)"
run-tests.sh
else
echo "✗ Merge failed"
exit 1
fi
}
ci_rerere_integration
Terminal window
# Enable rerere
git config rerere.enabled true
# Configure automatic resolution
git config rerere.autoUpdate true # Stage resolved files
# Configure storage
git config rerere.enabled true # Basic enable
git config gc.rerereResolved 60 # Days to keep resolutions
git config gc.rerereUnresolved 15 # Days to keep unresolved
# Configure for large teams
git config rerere.enabled true
git config rerere.share true # Share resolutions (experimental)
Terminal window
# Always review auto-applied resolutions
git rerere status # Check what was applied
git diff # Verify the results
# Backup before complex operations
cp -r .git/rr-cache .git/rr-cache.backup
# Test rerere behavior
git config rerere.enabled true
# Perform test merge with conflicts
# Verify behavior
# Monitor rr-cache size
watch -n 60 'du -sh .git/rr-cache'
Terminal window
# When to use rerere:
# - Long-lived branches with frequent rebases
# - Teams with recurring merge conflicts
# - Automated processes with predictable conflicts
# - Development workflows with repeated merges
# When to avoid rerere:
# - Short-lived branches
# - One-time merges
# - Conflicts requiring different resolutions
# - Security-sensitive code (review all resolutions)
# Best practices:
# - Enable rerere early in project
# - Review auto-applied resolutions
# - Clean up old resolutions regularly
# - Document complex resolution strategies
#!/bin/bash
# Rebase workflow enhanced with rerere
rerere_rebase_workflow() {
local target_branch="${1:-main}"
echo "Rebasing with rerere support onto $target_branch"
# Ensure rerere is enabled
if [ "$(git config rerere.enabled)" != "true" ]; then
echo "Enabling rerere for better rebase experience"
git config rerere.enabled true
fi
# Fetch latest changes
git fetch origin "$target_branch"
# Attempt rebase
if git rebase "origin/$target_branch"; then
echo "✓ Rebase completed successfully"
# Check if rerere helped
if git rerere status | grep -q .; then
echo "Rerere applied resolutions for:"
git rerere status
fi
else
echo "Rebase encountered conflicts"
# Show remaining conflicts
git rerere remaining
# Guide user through resolution
echo "Resolve conflicts, then run:"
echo " git add <resolved-files>"
echo " git rebase --continue"
echo ""
echo "Rerere will record your resolutions for next time"
fi
}
rerere_rebase_workflow "main"
Terminal window
# Use rerere to train conflict resolution
train_conflict_resolution() {
echo "Training conflict resolution with rerere"
# Create test scenario
git checkout -b training
# Make conflicting changes
echo "conflicting change 1" > conflict.txt
git add conflict.txt
git commit -m "Add conflicting change 1"
git checkout main
echo "conflicting change 2" > conflict.txt
git add conflict.txt
git commit -m "Add conflicting change 2"
# Enable rerere
git config rerere.enabled true
# Perform merge to create conflict
if ! git merge training 2>/dev/null; then
echo "Conflict created. Resolve it:"
echo "Edit conflict.txt, then:"
echo " git add conflict.txt"
echo " git commit"
echo ""
echo "Rerere will remember this resolution"
fi
}
train_conflict_resolution
Terminal window
# Maintain rerere database
rerere_maintenance() {
echo "Performing rerere maintenance"
# Check rerere status
if [ "$(git config rerere.enabled)" = "true" ]; then
echo "Rerere is enabled"
# Show current status
echo "Recorded resolutions:"
git rerere status
# Clean up old resolutions
git rerere gc
# Show cache statistics
echo "Cache statistics:"
find .git/rr-cache -type f | wc -l
du -sh .git/rr-cache 2>/dev/null || echo "No rr-cache directory"
else
echo "Rerere is not enabled"
read -p "Enable rerere? (y/N): " enable
if [[ "$enable" == "y" ]]; then
git config rerere.enabled true
echo "Rerere enabled"
fi
fi
}
rerere_maintenance
Terminal window
# Debug rerere issues
debug_rerere() {
echo "Debugging rerere issues"
# Check if enabled
if [ "$(git config rerere.enabled)" != "true" ]; then
echo "Rerere is not enabled"
git config rerere.enabled true
return
fi
# Check rr-cache directory
if [ ! -d .git/rr-cache ]; then
echo "rr-cache directory does not exist"
mkdir -p .git/rr-cache
fi
# Check permissions
if [ ! -w .git/rr-cache ]; then
echo "rr-cache directory not writable"
chmod 755 .git/rr-cache
fi
# Test with simple conflict
echo "Testing rerere with simple conflict..."
# Create test scenario
}
debug_rerere
Terminal window
# Handle incorrect auto-applied resolutions
fix_incorrect_resolution() {
echo "Fixing incorrect rerere resolution"
# Check what was applied
git rerere status
# Undo the auto-resolution
git checkout HEAD -- <auto-resolved-file>
# Resolve conflict manually
# Edit file to fix conflict properly
git add <file>
# Forget the incorrect resolution
git rerere forget <file>
# Continue with merge/rebase
git commit # or git rebase --continue
}
fix_incorrect_resolution
Terminal window
# Manage rerere storage
manage_rerere_storage() {
echo "Managing rerere storage"
# Check storage usage
du -sh .git/rr-cache/
# List all recorded resolutions
find .git/rr-cache -name "postimage" | while read -r file; do
dir=$(dirname "$file")
echo "Resolution: $(basename "$dir")"
done
# Clean up old resolutions
find .git/rr-cache -type f -mtime +90 -delete
# Reorganize storage
git rerere gc
}
manage_rerere_storage
Terminal window
# Optimize rerere performance
optimize_rerere_performance() {
echo "Optimizing rerere performance"
# Limit cache size
git config gc.rerereResolved 30 # Keep less time
# Clean up frequently
git rerere gc
# Use faster storage if possible
# (Consider moving rr-cache to faster disk)
# Monitor performance
time git rerere status
}
optimize_rerere_performance
Terminal window
# Handle rerere in shared repositories
handle_shared_rerere() {
echo "Handling rerere in shared repositories"
# Check if sharing is desired
if [ -d .git/rr-cache ]; then
echo "Local rerere cache exists"
# Option 1: Keep local
echo "Keeping rerere local to developer"
# Option 2: Share via repository
# cp -r .git/rr-cache .git-shared/
# git add .git-shared
# git commit -m "Share rerere resolutions"
# Option 3: Share via network storage
# mount network storage to .git/rr-cache
fi
echo "Shared rerere setup complete"
}
handle_shared_rerere
#!/bin/bash
# Long-term feature development with rerere
long_term_feature_workflow() {
local feature_name="$1"
echo "Setting up long-term feature development: $feature_name"
# Enable rerere early
git config rerere.enabled true
# Create feature branch
git checkout -b "feature/$feature_name"
# Document rerere benefits
cat << 'EOF'
Rerere Benefits for Long-Term Features:
1. Conflict Resolution Learning:
- First conflict resolution is recorded
- Future similar conflicts resolve automatically
- Reduces repetitive work
2. Rebase-Friendly Development:
- Frequent rebases become easier
- Conflict resolution time decreases
- More confident rebasing
3. Team Collaboration:
- Share resolution strategies
- Consistent conflict handling
- Faster integration
Usage Tips:
- Enable rerere at branch start
- Review auto-applied resolutions
- Clean up when feature completes
- Share complex resolutions with team
EOF
echo "Long-term feature workflow configured"
echo "Rerere will help with recurring conflicts"
}
long_term_feature_workflow "user-authentication-system"
Terminal window
# Rerere for open source maintenance
open_source_maintenance() {
echo "Setting up rerere for open source maintenance"
# Enable rerere for upstream work
git config rerere.enabled true
# Configure for frequent rebasing
git config rerere.autoUpdate true
# Set up workflow
cat << 'EOF'
Open Source Maintenance with Rerere:
1. Fork Management:
- Keep fork updated with upstream
- Frequent rebases cause conflicts
- Rerere remembers resolutions
2. Patch Series Maintenance:
- Maintain multiple patches
- Rebase frequently for updates
- Rerere handles recurring conflicts
3. Review Integration:
- Apply review feedback
- Rebase and re-submit
- Rerere maintains resolutions
Workflow:
git checkout feature-branch
git rebase upstream/main # Rerere helps here
# Resolve any new conflicts
# Rerere records for next time
git push origin feature-branch
EOF
echo "Open source maintenance workflow configured"
}
open_source_maintenance
Terminal window
# Optimize CI/CD with rerere
ci_rerere_optimization() {
echo "Optimizing CI/CD pipelines with rerere"
# Enable rerere in CI
git config rerere.enabled true
# Pre-populate common resolutions
if [ -d ci-rerere-cache ]; then
cp -r ci-rerere-cache .git/rr-cache
fi
# Run CI process
echo "Running CI with rerere optimization..."
# Example: Automated merging
if git merge --no-edit automated-branch 2>/dev/null; then
echo "✓ Merge successful with rerere"
else
echo "Merge had conflicts - resolving..."
# Apply any available rerere resolutions
git rerere remaining | while read -r file; do
if git rerere diff "$file" >/dev/null 2>&1; then
echo "Auto-resolving $file with rerere"
# Resolution already applied
fi
done
# Check if all conflicts resolved
if git diff --quiet; then
git commit --no-edit
echo "✓ Conflicts resolved with rerere"
else
echo "✗ Manual conflict resolution required"
exit 1
fi
fi
# Save updated cache for future runs
cp -r .git/rr-cache ci-rerere-cache/
echo "CI/CD optimization complete"
}
ci_rerere_optimization
Terminal window
# Use rerere for conflict resolution training
conflict_resolution_training() {
echo "Setting up conflict resolution training with rerere"
# Create training repository
mkdir training-repo
cd training-repo
git init
# Enable rerere
git config rerere.enabled true
# Create base content
echo "base content" > file.txt
git add file.txt
git commit -m "Initial commit"
# Create conflicting branches
git checkout -b branch-a
echo "content from branch A" >> file.txt
git commit -am "Add branch A content"
git checkout main
git checkout -b branch-b
echo "content from branch B" >> file.txt
git commit -am "Add branch B content"
# Document training exercise
cat << 'EOF'
Conflict Resolution Training Exercise:
1. Try to merge branch-a into branch-b:
git checkout branch-b
git merge branch-a
2. Resolve the conflict manually
- Edit file.txt to include both changes
- git add file.txt
- git commit
3. Rerere has now recorded the resolution
4. Try merging again in different scenario:
git checkout -b test-merge
git merge branch-a # Should resolve automatically
5. Verify rerere worked:
git rerere status
git rerere diff
Learning Points:
- Rerere remembers exact conflict resolutions
- Same conflicts resolve automatically
- Different conflicts still need manual resolution
- Review auto-applied resolutions
EOF
echo "Training setup complete"
echo "Follow the exercise in the documentation above"
}
conflict_resolution_training
Terminal window
# Use rerere during repository migration
migration_rerere_support() {
local source_repo="$1"
local target_repo="$2"
echo "Using rerere to aid repository migration"
# Enable rerere
git config rerere.enabled true
# During migration, conflicts may occur
# Rerere can help resolve recurring conflicts
echo "Migration rerere support configured"
echo "Rerere will help with any recurring conflicts during migration"
# Example migration workflow:
cat << 'EOF'
Migration with Rerere Support:
1. Start migration process
2. Enable rerere before first conflicts
3. Resolve conflicts manually first time
4. Rerere records resolutions
5. Subsequent similar conflicts resolve automatically
6. Review all auto-applied resolutions
7. Complete migration with confidence
EOF
}
migration_rerere_support "/path/to/source" "/path/to/target"

What’s the difference between rerere and manual conflict resolution?

Section titled “What’s the difference between rerere and manual conflict resolution?”

Rerere automatically applies previously recorded conflict resolutions when the same conflicts occur again, while manual resolution requires resolving each conflict instance individually.

Use git config rerere.enabled true to enable rerere globally or for the current repository.

Can rerere resolve all types of conflicts?

Section titled “Can rerere resolve all types of conflicts?”

No, rerere only resolves conflicts that have identical pre-conflict states to previously recorded resolutions. Different conflicts still need manual resolution.

Use git rerere status to see current recordings, git rerere diff to see the recorded resolutions, and git rerere remaining to see conflicts that can be auto-resolved.

Rerere is generally safe but can apply incorrect resolutions if conflicts are similar but not identical. Always review auto-applied resolutions, especially for critical code.

How do I disable rerere for a specific operation?

Section titled “How do I disable rerere for a specific operation?”

You can temporarily disable with git -c rerere.enabled=false , or disable globally and re-enable when needed.

Can rerere work across different repositories?

Section titled “Can rerere work across different repositories?”

Rerere resolutions are local to each repository, but you can copy .git/rr-cache directories between repositories to share resolutions.

Use git rerere gc to clean up old recordings, or manually delete old files from .git/rr-cache.

Yes, rerere stores conflict resolutions in .git/rr-cache, which can grow over time. Regular cleanup with gc helps manage size.

Yes, but with caution. Ensure the script reviews auto-applied resolutions and handles cases where conflicts differ from recorded resolutions.

How do I share rerere resolutions with my team?

Section titled “How do I share rerere resolutions with my team?”

Copy .git/rr-cache directories, commit them to the repository, or use shared network storage for the rr-cache directory.

What’s the difference between rerere and gitattributes conflict markers?

Section titled “What’s the difference between rerere and gitattributes conflict markers?”

Rerere records complete conflict resolutions, while gitattributes can only specify conflict marker styles. Rerere provides actual resolution reuse.

No, rerere only works with text files where conflicts can be detected and resolved using diff/patch mechanisms.

How do I forget a specific rerere resolution?

Section titled “How do I forget a specific rerere resolution?”

Use git rerere forget to forget recorded resolutions for specific files or paths.

Yes, rerere works independently of merge tools. It records the final resolved state regardless of how conflicts were resolved.

Can rerere be used with rebase operations?

Section titled “Can rerere be used with rebase operations?”

Yes, rerere works with rebase, merge, and other operations that create conflicts. It’s particularly useful for frequent rebasing.

  1. Long-Lived Branch Management: Automatically resolve recurring conflicts in long-term feature branches
  2. Frequent Rebase Workflows: Reduce conflict resolution time during frequent rebasing
  3. Team Collaboration: Share conflict resolution strategies across team members
  4. CI/CD Optimization: Speed up automated merge processes with recorded resolutions
  5. Conflict Resolution Training: Learn and document conflict resolution patterns
  6. Repository Maintenance: Maintain consistent conflict resolution approaches