# Automatically commit a directory to git I use this script to regularly backup my Emacs org-roam files to a git repository. It requires you to already have initialised the directory in a remote git repository. ```bash #!/usr/bin/env bash ORG_PATH=$1; cd $ORG_PATH; if [[ ! `git status --porcelain` ]]; then echo "No changes to repository; skipping this commit."; exit 1; fi echo "Committing changes to org (${ORG_PATH}) to git"; DATE=$(date +%Y%m%d%H%M%S); git add .; git config commit.gpgsign false; git commit -a -m "Autocommit from \`org-git.sh\` at ${DATE}"; git push; ``` This can be added to your user's crontab like so: ```sh # m h dom mon dow command */5 * * * * bash /path/to/script.sh /path/to/directory >/dev/null 2>&1; ``` My example will run every 5 minutes.