i have a solution, but not for your code.
i keep all my scripts in folders that are backed up on the cloud, mainly Google Drive, Dropbox, and OneDrive, with their respective syncing apps installed.
If i ever delete, or otherwise completely fubar my code i can just grab a previous version from the cloud, saves me from many hassles and headaches.