This guide covers advanced Twin features, complex rsync patterns, and real-world workflow examples.
- Custom Rsync Flags
- Exclusion Patterns
- Bidirectional Sync
- Multiple Remotes
- Configuration Management
- Workflow Examples
- Performance Optimization
Twin saves custom rsync flags for each remote, so you set them once and they persist.
Without customization, Twin uses: -avu --progress
-a: Archive mode (preserves permissions, timestamps, etc.)-v: Verbose output-u: Skip files newer on receiver--progress: Show transfer progress
twin -e "-av --dry-run" myserver
# Test what would happen without making changes
twin -e "-avu --delete" myserver
# CAUTION: Deletes files on remote that don't exist locally
twin -e "-avz --compress-level=9" myserver
# Maximum compression for slow connections
twin -e "-av --checksum" myserver
# Use checksums instead of timestamps (slower but more accurate)# Show detailed progress
twin -e "-avu --progress" myserver
# Delete extraneous files
twin -e "-avu --delete" myserver
# Preserve hard links
twin -e "-avuH" myserver
# Limit bandwidth (KB/s)
twin -e "-avu --bwlimit=1000" myserver
# Compress during transfer
twin -e "-avuz" myserverExclude files and directories from sync using --exclude.
# Exclude single directory
twin -e '--exclude=node_modules/' myserver
# Exclude single file pattern
twin -e '--exclude=*.log' myserver
# Exclude multiple patterns
twin -e '--exclude=*.pyc --exclude=__pycache__/' myservertwin -e '-avu --exclude=.venv/ --exclude=*.pyc --exclude=__pycache__/ --exclude=*.egg-info/' myservertwin -e '-avu --exclude=node_modules/ --exclude=.npm/ --exclude=package-lock.json' myservertwin -e '-avu --exclude=*.h5 --exclude=*.ckpt --exclude=*.pth --exclude=*.parquet --exclude=data/' myservertwin -e '-avu --exclude=.git/ --exclude=.DS_Store --exclude=.env --exclude=*.swp' myserver# Exclude hidden files except .gitignore
twin -e '--exclude=.* --include=.gitignore' myserver
# Exclude by size (files larger than 100MB)
twin -e '--max-size=100m' myserver
# Exclude everything then selectively include
twin -e '--exclude=* --include=*.py --include=*.md' myserverCreate .rsyncignore pattern:
# Create exclude file
cat > .twin-exclude << EOF
*.log
*.tmp
.DS_Store
node_modules/
.venv/
EOF
# Use in twin command
twin -e "--exclude-from=.twin-exclude" myserverTwin supports bidirectional synchronization with conflict handling.
twin -p myserver
# 1. Pushes local changes to remote
# 2. Pulls remote changes to localtwin -P myserver
# Only pulls from remote to localCase 1: File modified on both sides
Rsync will use the newer file by default (timestamp-based). For checksum-based:
twin -e "-av --checksum" -p myserverCase 2: File deleted locally, modified remotely
# Without --delete, remote file persists
twin -p myserver
# With --delete, remote file is deleted
twin -e "-av --delete" -p myserverSync the same local directory to multiple remote hosts.
cd ~/my-project
# Pair with staging server
twin staging /var/www/staging
# Pair with production server
twin production /var/www/production
# Pair with backup server
twin backup /mnt/backups/my-projectEach remote gets its own config:
ls -la | grep twin
# .twin.staging.json
# .twin.production.json
# .twin.backup.json# Sync to staging first
twin staging
# Test on staging
# ...
# Deploy to production
twin production
# Backup
twin backup# Read entire config
./twin-config read myserver
# Read specific field
./twin-config read myserver --field remote_path
./twin-config read myserver --field rsync_flags
./twin-config read myserver --field git_integration.setup_complete# Update remote path
./twin-config write myserver --remote-path /new/path
# Update rsync flags
./twin-config write myserver --rsync-flags "-avu --delete"
# Update git integration
./twin-config write myserver --git-local-name newname{
"remote_path": "/var/www/myapp",
"rsync_flags": "-avu --progress --exclude=node_modules/",
"last_sync": "2025-11-23T10:30:00",
"git_integration": {
"local_remote_name": "staging",
"remote_remote_name": "laptop",
"setup_complete": true
}
}# Remove config file to reset pairing
rm .twin.myserver.json
# Next twin command will create fresh pairing
twin myserver /remote/path# Initial setup
cd ~/my-web-app
twin prod /var/www/myapp
# Daily workflow
git add .
git commit -m "Add feature"
git push origin main
# Deploy to production
twin -e "-avu --delete --exclude=.git/" prod
# Check logs on production
ssh prod "tail -f /var/log/app.log"# On laptop
cd ~/projects/myapp
twin desktop ~/projects/myapp
# Work on laptop
# ... make changes ...
twin desktop
# Switch to desktop
# On desktop
cd ~/projects/myapp
twin -P laptop # Pull laptop changes
# ... continue working ...
twin laptop # Push desktop changes back# Exclude large binary files from git, sync with rsync
twin -e '-avu --exclude=.git/ --include=*.h5 --include=*.parquet' mlserver
# Then use git for code only
git add *.py *.md
git commit -m "Update model code"
git push origin main# Setup backup remote
twin backup /mnt/backups/my-project
# Regular backups (keeps deleted files on backup)
twin backup
# Full mirror backup (deletes old files)
twin -e "-avu --delete" backup# Test with dry-run
twin -e "-av --dry-run" prod
# Review what would change
# ...
# Execute actual sync
twin -e "-av" prodUseful for slow network connections:
# Enable compression
twin -e "-avuz" myserver
# Maximum compression
twin -e "-avuz --compress-level=9" myserverTrade-off: Uses more CPU, saves bandwidth.
Prevent saturating network:
# Limit to 1000 KB/s
twin -e "-avu --bwlimit=1000" myserver
# Limit to 100 KB/s (very slow connection)
twin -e "-avu --bwlimit=100" myserverResume interrupted transfers:
twin -e "-avuP" myserver
# -P is shorthand for --partial --progressFor multiple small files:
# Note: rsync doesn't natively support parallel transfers
# Use multiple twin commands for different directories:
twin -e "-avu src/" myserver &
twin -e "-avu docs/" myserver &
wait# Faster: timestamp-based (default)
twin myserver
# Slower but more accurate: checksum-based
twin -e "-av --checksum" myserverUse checksums when:
- Files modified without timestamp changes
- Syncing across different filesystems
- Ensuring data integrity is critical