A Docker-based solution to create complete backups of private GitHub repositories, including all branches, history, and LFS files.
- ✅ All branches and tags
- ✅ Complete commit history
- ✅ All Git LFS files
- ✅ All refs and remote tracking info
- ✅ Compressed into a single
.tar.gz
archive
- Clone this gist and set up credentials:
# Create .env file with your GitHub credentials
cat > .env << EOF
GITHUB_TOKEN=your_personal_access_token_here
GITHUB_USER=yourusername
REPO_NAME=your-repo-name
EOF
- Run the backup:
# Create the backup
docker compose run --rm github-backup
- Find your backup:
ls -lh backups/
# Output: your-repo-name-backup-2024-01-15-143022.tar.gz
# Extract the archive
tar -xzf backups/your-repo-name-backup-*.tar.gz
# Option 1: Create a normal repo from backup
git clone your-repo-name.git restored-repo
cd restored-repo
git branch -a # Shows all branches
# Option 2: Push to a new GitHub repo
cd your-repo-name.git
git push --mirror https://github.com/username/new-repo.git
git lfs push --all https://github.com/username/new-repo.git
- Docker and Docker Compose
- GitHub Personal Access Token with
repo
scope - Enough disk space for your repository + compressed archive
- Uses
git clone --mirror
to create a complete bare repository - Fetches all LFS objects with
git lfs fetch --all
- Compresses everything into a timestamped
.tar.gz
archive - Cleans up temporary files, leaving only the archive
- The backup is a "bare" repository (no working files, just Git data)
- Archives are timestamped for versioning
- Compression uses gzip level 6 (balanced speed/size)
- For large repositories with many LFS files, ensure adequate disk space
If folders like refs/heads/
appear empty after extraction, this is normal. Branches are often stored in the packed-refs
file. Verify your backup with:
git clone your-repo-name.git test-restore
cd test-restore
git branch -a # Should list all branches