Saturday, 25 June 2016

Set up a Git Repository on Raspberry Pi with SSH

I have a Raspberry Pi on my local network and I wanted to set it up as a git repository on my local network.

First thing I did was SSH onto my Raspberry Pi and create a directory for the repo.
mkdir <project name>

Next I needed to set up the Git repo. 
cd <project name>
git init --bare

Now the repo was set up and I could clone it to any device on my network.
I cloned the repo onto my mac
git clone ssh://<username>@<raspberry pi ip or hostname>:<path to repo>/<repo name>

The repo was now cloned on my mac, I could make local commits. But to push to the remote repo over SSH, I needed to specify what branch was needed. When I performed git init --bare, no branches were actually created, so I needed to create and push to a new remote branch.
git push origin master