Skip to content

Instantly share code, notes, and snippets.

@tcard
Last active October 5, 2022 05:35
Show Gist options
  • Save tcard/b35eb6759dd3253aab94f62728234873 to your computer and use it in GitHub Desktop.
Save tcard/b35eb6759dd3253aab94f62728234873 to your computer and use it in GitHub Desktop.
Daily Git commit cronjob
#!/usr/bin/env bash
set -euo pipefail
function dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo " (dirty)"
}
current_branch="$(git rev-parse --abbrev-ref HEAD)"
git add . # TODO: Save and then restore stage state
description="$(date +'%F %T') $current_branch$(dirty): $(git show -s --format='%h %s')"
git commit --allow-empty -m "$description"
git checkout -b daily || (
git checkout daily
(
(git diff daily "$current_branch" | git apply) &&
(git add . && git commit -m "$description")
) || true
)
git checkout "$current_branch"
git reset --soft HEAD~1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment