Skip to content

Instantly share code, notes, and snippets.

@xurizaemon
Last active October 7, 2021 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xurizaemon/6af2757742603580f14415e9848786c7 to your computer and use it in GitHub Desktop.
Save xurizaemon/6af2757742603580f14415e9848786c7 to your computer and use it in GitHub Desktop.
journal git auto commit

Auto-sync

This is how I currently auto-push changes to my work/lab journal repo. It works across multiple systems with minimal clashes (in part because I don't switch devices or edit journal in multiple places concurrently, perhaps). $EDITOR takes care of asking me to resolve conflicts (and shows git diff when appropriate).

I've put it here to share and to invite input on how it might be improved.

In reply to https://twitter.com/majorhayden/status/1446179887606386689

journal-git.sh

#!/bin/bash
#
JOURNAL_PATH=/path/to/journal
DATE=$( date +"%Y-%m-%d %H:%M" )
HOSTNAME=$( hostname )
BRANCH=main

cd $JOURNAL_PATH
git add -A .
git commit -m "journal update on ${HOSTNAME} @ ${DATE}"
git pull origin $BRANCH --no-edit
git push origin $BRANCH

cron entry

I vary the minutes per host so that they don't attempt to push at once.

4,19,34,49 * * * *         /home/chris/bin/journal-git.sh 2>&1 | logger -t journal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment