Let’s imagine a scenario where we have an IoT device which is unable to reach our git repository due to some external factors (security, networking, etc.) but we still want to push code to it, maintain version control, and run that code on the device.
The IoT device is, however, reachable from our laptop over our Tailscale network (or another form of VPN). As one of my colleagues says, “We forget that before GitHub existed we all just pushed to our git repos over SSH.” We still do that, but GitHub has hidden much of it from us.
Here is a diagram of the situation:
We would like to git pull from our Git Server repo (our normal flow), make code changes, and git push them to the IoT device.
To git push to the IoT device, we just need to configure a git remote over SSH on our laptop, pointing to a bare repository on the IoT device. Enabling Tailscale SSH on the IoT device handles authentication for us, so we don’t need to manage keys. Example of a simple flow that can be adapted as needed:
IoT Device
On device iot_test we initialize a bare git repository repo in $HOME/workspace.
stefan@iot_test:~/workspace/repo$ git init
Laptop
With a cloned repo from our Git server as usual.
git checkout --orphan dev_feature1 create an orphaned branch dev_feature1.
git remote add iot_test_repo ssh://stefan@iot_test:/home/stefan/worksapce/repo the most important part adding a git remote pointing to the IoT device repository over SSH.
git reset
git add src/feature1 add the code we want to send over to the IoT device.
git commit -m "added feature one"
git push iot_test_repo dev_feature1 push the dev_feature1 brach which includes the code we want to deliver to the iot_test_repo remote we added.
IoT Device
Switch over to the brach we just pushed to and get our changes/code.
stefan@iot_test:~/workspace/repo$ git checkout dev_feature1 switch to the branch we just pushed from the laptop.
stefan@iot_test:~/workspace/repo$ git log
commit .......... (HEAD -> dev_feature1)
Author: ..........
Date: ..........
added feature one
stefan@iot_test:~/workspace/repo$ tree
.
└── src
└── feature1