Automatic commit to a repository using shell script

☕️ 1 min read

I use the following snippet to make an automatic commit to my braindump repository:

#!/usr/bin/env bash
set -euo pipefail

org_head=$(git rev-parse HEAD)

printf "Deploying updates to GitHub...\033[0m\n"
printf "\033[0;32mDeploying commit $org_head of '🧠 braindump' \n\033[0m"

## Commit and push
if [[ `git status --porcelain` ]]; then
  git add .

  git commit -m "🧠 Automatic braindump commit $(date)

  This is a commit of '$org_head'
  Respository: github.com/helderburato/braindump"
else
  printf "No changes detected.\n"
fi

git push origin master