01
Complex Merge Conflicts
Resolve challenging merge scenarios that break standard workflows
š„ Binary File Conflicts
Images, docs, or binaries in conflict
# Choose version explicitly
git checkout --ours path/to/binary-file
git checkout --theirs path/to/binary-file
# Manual selection with attributes
echo "*.pdf merge=ours" >> .gitattributes
git add .gitattributes
ā” Recursive Merge Hell
Deep conflicts across multiple branches
# Reset and use 3-way merge
git merge --abort
git merge --strategy=recursive --strategy-option=patience
# Alternative: octopus merge for multiple branches
git merge branch1 branch2 branch3
š Submodule Conflicts
Submodule pointer conflicts
# Update submodule to latest
git submodule update --remote
git add submodule-name
# Force submodule to specific commit
cd submodule-name
git checkout abc123
cd ..
git add submodule-name
Advanced Conflict Resolution
# Ultimate conflict analyzer
#!/bin/bash
analyze_complex_conflicts() {
echo "=== CONFLICT ANALYSIS ==="
# Show conflict summary
git diff --name-only --diff-filter=U | while read file; do
echo "CONFLICTED: $file"
# Count conflict markers
conflicts=$(grep -c "<<<<<<< HEAD" "$file" 2>/dev/null || echo "0")
echo " Conflicts: $conflicts"
# Show conflict context
grep -n -A2 -B2 "<<<<<<< HEAD" "$file" 2>/dev/null || true
echo ""
done
# Suggest resolution strategy
echo "=== SUGGESTED STRATEGY ==="
file_count=$(git diff --name-only --diff-filter=U | wc -l)
if [[ $file_count -gt 10 ]]; then
echo "ā ļø MASS CONFLICT: Consider merge --abort and rebase strategy"
elif [[ $file_count -gt 5 ]]; then
echo "ā” MEDIUM CONFLICT: Use merge tool or manual resolution"
else
echo "ā
MANAGEABLE: Manual resolution recommended"
fi
}
# Execute analysis
analyze_complex_conflicts
02
Performance Debugging
Optimize slow Git operations and large repository performance
Performance Profiling
# Git operation timing
GIT_TRACE_PERFORMANCE=1 git status
GIT_TRACE_PERFORMANCE=1 git log --oneline -100
# Repository size analysis
git count-objects -vH
git rev-list --objects --all | \
git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize)' | \
awk '{sum+=$3} END {print "Total size:", sum/1024/1024 "MB"}'
# Find large files
git rev-list --objects --all | \
git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' | \
awk '$3 > 1048576 {print $3/1048576 "MB", $4}' | sort -nr
Quick Optimizations
šļø Repository Cleanup
# Aggressive optimization
git gc --aggressive --prune=now
git repack -ad
git reflog expire --expire=now --all
š Large File Management
# Remove large files from history
git filter-branch --tree-filter 'rm -f large-file.zip' HEAD
git push --force
# Use Git LFS for future large files
git lfs track "*.zip"
03
Network & Remote Issues
Debug connectivity and synchronization problems
š Connection Timeouts
# Increase timeouts
git config --global http.postBuffer 524288000
git config --global http.timeout 600
# Use SSH instead of HTTPS
git remote set-url origin git@github.com:user/repo.git
š Authentication Failures
# Clear credential cache
git credential-manager-core erase
echo "url=https://github.com" | git credential fill
# Test SSH connection
ssh -T git@github.com
ā” Sync Conflicts
# Force sync with remote
git fetch --all
git reset --hard origin/main
# Partial clone for large repos
git clone --filter=blob:limit=1m <url>
04
Workflow Edge Cases
Handle unusual scenarios and workflow breakdowns
š Detached HEAD Recovery
# Create branch from detached HEAD
git branch recovery-branch
git checkout recovery-branch
# Or merge back to main
git checkout main
git merge HEAD@{1}
šļø Branch Pointer Corruption
# Recreate branch from reflog
git reflog show branch-name
git branch branch-name-fixed <commit-hash>
# Update branch pointer
git update-ref refs/heads/branch-name <commit-hash>
ā ļø Partial Commits Missing
# Find lost commits
git fsck --lost-found
ls .git/lost-found/commit/
# Recover specific commit
git show <lost-commit-hash>
git branch recovery <lost-commit-hash>
Emergency Troubleshooting Script
#!/bin/bash
# Git Emergency Troubleshooter
emergency_diagnosis() {
echo "šØ GIT EMERGENCY DIAGNOSIS"
echo "========================="
# Basic health
echo "Repository Status:"
git status --porcelain | head -10
# Performance check
echo -e "\nPerformance Metrics:"
time git log --oneline -1 >/dev/null
# Remote connectivity
echo -e "\nRemote Status:"
git remote -v | while read name url type; do
if [[ "$type" == "(fetch)" ]]; then
timeout 10s git ls-remote "$name" >/dev/null 2>&1 && \
echo "ā
$name: OK" || echo "ā $name: FAILED"
fi
done
# Conflict check
echo -e "\nActive Conflicts:"
git diff --name-only --diff-filter=U | wc -l | \
xargs echo "Conflicted files:"
# Repository size
echo -e "\nRepository Size:"
du -sh .git/ 2>/dev/null || echo "Unable to determine size"
echo -e "\nš§ Run 'git gc --aggressive' if performance is slow"
echo "š Check network if remote operations fail"
echo "ā” Use 'git mergetool' for conflict resolution"
}
# Execute diagnosis
emergency_diagnosis
05
Troubleshooting Mastery
Advanced Git debugging skills acquired - Ready for any complex issue
Conflict Resolution
Binary file conflicts
Recursive merge issues
Submodule conflicts
Performance Optimization
Large repository cleanup
Operation profiling
File size management
Network Debugging
Connection timeouts
Authentication fixes
Sync problem resolution
Edge Case Handling
Detached HEAD recovery
Branch pointer repair
Lost commit retrieval
š Phase 6 Complete - Emergency Operations Mastery!
6.1: Disaster Recovery
Critical repository recovery
6.2: Advanced Troubleshooting
Complex issue resolution
ā” Git Expert Status Achieved!
You've mastered every aspect of Git - from basics to emergency operations. You're now equipped to handle any Git challenge with confidence.
Mission Control
Git Master Certified