Using Git Bundle For Backups
To add suspenders to the git belt, use git bundle.
git bundle create ~/backups/backup-name-$(date +%Y%m%d).bundle --all
So, if my project is media-manager, then I use:
git bundle create ~/backups/media-manager-$(date +%Y%m%d).bundle --all
A git bundle is essentially a portable, single-file version of your repository. Here’s how to use it if disaster strikes:
Disaster Recovery Scenario
Let’s say you’ve lost your local repository and the remote repository is unavailable (GitHub down, account issues, etc.). Here’s how to recover using your bundle:
- Create a New Repository from the Bundle
Create a new directory for the restored repository
mkdir recovered-project
cd recovered-project
Initialize a new git repository
git init
Pull from the bundle file
git pull /path/to/myproject-20240501.bundle
This will restore:
All commits All branches that were included when creating the bundle All tags that were included The commit history and file contents
- Verify the Recovery
Check the branches
git branch -a
Look at the log
git log
Verify files are present
ls -la 3. Reconnect to Remote (If Available Later)
Add your remote again
git remote add origin https://github.com/yourusername/repository.git
When the remote is available again, push everything
git push --all origin
git push --tags origin
What Makes Bundles Powerful
Complete: Contains all objects and references Portable: Single file that can be stored anywhere Efficient: Compressed format Independent: Doesn’t require a server or network Think of a bundle as a complete snapshot of your repository at a point in time, stored in a single file that can be moved easily to external drives, cloud storage, etc.
Recommended Bundle Backup Frequency
For personal projects:
Before major refactoring or risky changes
Monthly for active projects
Quarterly for less active ones
Store these bundles somewhere separate from your working machine for true worst-case protection.