I bought a Pi 3 B+ and would like to have it auto clone/deploy new pushes (from a different machine) from a private github repo. I was just wondering how I would do that. I know I need a github web hook but I have no clue where to start. The Pi is going to be in a place I dont want to get to very often to update my code so this would make everything so much easier. Thanks
-
1Welcome to StackOverflow! Please follow our guidelines on [How to Ask a Question](https://stackoverflow.com/help/how-to-ask) to improve your chances of getting a good response. – Joseph Cho Nov 14 '18 at 01:33
3 Answers
You need to clone your repository to your Raspberry Pi
git clone git@github.com:your-username/your-repo-name.git
Then before starting your script you just pull new version from github to your local repository and run updated script
git pull origin master
example of starting script:
#!/bin/bash
cd /your-local-repository-path/
git pull origin master
python your-script.py &
Dont forget make start script executable sudo chmod 755 starting-script.sh
Then you can run your starting script /.starting-script.sh
It shoud pull latest version of remote repository to your local repository before running.
Hope it helps you.
-
Thanks! I was more specifically looking on how I could make it so that as soon as I push an update on another machine it'll automatically pull it and restart with the revisions. – briyoon Nov 15 '18 at 02:24
-
1OK. Then I recommend to you these articles: [How to check, if your repository is up-to-date](https://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git) and [How to restart script itself](https://stackoverflow.com/questions/11329917/restart-python-script-from-within-itself). You can checking git in some interval in loop or etc. If my answer helped you, mark it as solution please. thank you. – Koxo Nov 15 '18 at 12:08
-
Thank you so much for those articles! Do you know how to set up a webhook with github to communicate with my rPi? – briyoon Nov 15 '18 at 17:44
I figured it out. I just ended up creating a local Jenkins server and used a plugin to that would auto pull the repo from a webhook. to set up the webhook I made the local Jenkins server available to the internet so that the plugin would catch the webhook.

- 75
- 1
- 7
Maybe this could help out someone else.
Git-Auto-Deploy consists of a small HTTP server that listens for Webhook requests sent from GitHub, GitLab or Bitbucket servers. This application allows you to continuously and automatically deploy your projects each time you push new commits to your repository

- 3,940
- 1
- 8
- 24

- 93
- 4
- 14
-
This would be significantly easier than the original answer from 2018. – FrankDrebin893 Aug 02 '22 at 19:45