I have a set of Raspberry Pis and I need to back up the stuff I do on them, and ideally add some version control as that is always good.
So the idea is to set up a git server on my Windows machine, giving me the ability to both version control the stuff I am doing, and back it up through the pre-existing Windows backup. And the assumption is that anything not in git can be recreated easily enough.
This and the follow up here are the best tutorials I've come across describing this, but full details here:
Install SSH
I'm using the new Microsoft supported OpenSSH.
- unzip the package at C:\Program Files\OpenSSH-Win64 and follow the installation instructions.
- Check the installation by connecting to the Windows machine through SSH.
Note that there OpenSSH isn't yet mature enough for this to work correctly. Worth instead using Bitvise SH Server which is free for limited use.
Install Git
- Download git for Windows and install. Suggest install either git bash, or git bash + cmd option.
- Update PATH to add C:\Program Files\Git\mingw64\libexec\git-core and C:\Program Files\Git\bin
- Create a new file in C:\Program Files\Git\bin named gup.sh. his removes additional single quotes that are added by ssh from Linux to windows:
- Create a second new file named grp.sh:
How to use:
To clone:
git clone -u 'sh gup.sh' user@laptop:C:/Temp/new-project.git
To push:
git push --exec 'sh grp.sh' user@laptop:C:/Temp/new-project.git master
To pull:
To pull:
git pull --upload-pack 'sh gup.sh' user@laptop:C:/Temp/new-project.git
Alternatively, update ~/.gitconfig using (see here):
git config --global remote.origin.uploadpack 'sh gup.sh'
git config --global remote.origin.receivepack 'sh grp.sh'
To create an empty project:
On remote server:
mkdir new-project.git
cd new-project.git
git init --bare
On local machine:
cd new-project
cd new-project
git init
git add *
git commit -m "Initial commit"
git remote add origin user@laptop:C:/Temp/new-project.git
git push origin master
git add *
git commit -m "Initial commit"
git remote add origin user@laptop:C:/Temp/new-project.git
git push origin master
To set up Public Key Authentication
On remote server (linux):ssh-keygen –t rsa
or (Windows):
ssh-keygen.exe -t rsa -f id_rsa
(For OpenSSH) Copy the contents of ~/.ssh/rsa_id.pub and add to %systemdrive%\users\user\\.ssh\authorized_keys on host.
Alternatively...
Use Bitvise SSH Server as it is better...