Automatically push your Git repos before computer shutdown
I use two computers, my desktop computer located at home and set up for work and play and a work notebook (company provided) that I usually leave at the office. I use both computers for work and sometimes I forget to do ‘git push’ when working at my home desktop computer. The next day, when using the work notebook, I wonder where the code from the previous day has disappeared.
Of course, I can solve it by connecting to my home Raspberry Pi through SSH, waking the desktop computer over LAN from it, connecting to it using Remote Desktop to do the ‘git push’ .. not really a simple solution, there must be a better way.
So I came up with a really simple PowerShell script to iterate to a directory with git projects and execute ‘git push’ on all of them
Get-ChildItem D:\Projects\Apps | ForEach-Object {
cd $_.FullName
git push
}
To make the script execute on each computer shutdown, run gpedit.msc and go to Computer Configuration | Windows Settings | Scripts (Startup/Shutdown) | Shutdown and add the script. Adding the script just by referencing the .ps1 file did not work for me, I had to add the path to PowerShell (%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe) with the script as a parameter.