Skip to content

Instantly share code, notes, and snippets.

@the-bokya
Last active October 24, 2025 22:50
Show Gist options
  • Select an option

  • Save the-bokya/03332474bc69fc8082c3e92248db6750 to your computer and use it in GitHub Desktop.

Select an option

Save the-bokya/03332474bc69fc8082c3e92248db6750 to your computer and use it in GitHub Desktop.
Git auto build and deploy latest changes
#!/bin/bash
# $1 should be the directory for the git repo
cd $1
git fetch
git_diff=$(git diff origin/main)
echo $git_diff
if [ -z "$git_diff" ]
then
exit
fi
git reset --hard origin/main
# $2 should be the path to the deploy script
# e.g., "/root/scripts/deploy.sh"
# you could just put stuff like npm install && npm run build && yada-yada here too
$2
# add this to the crontab config
# e.g., * * * * * /bin/bash -c '/root/scripts/push-to-deploy.sh "/root/repos/the-bokya.github.io" "/root/scripts/deploy.sh" &> "/root/logs/deploy/$(date).log"'
# runs every minute (overkill, ik) and saves logs with date formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment