Files
wiki/Automatic_Git_Commits.md

2.3 KiB

title, description, published, date, tags, editor, dateCreated
title description published date tags editor dateCreated
Automatic Git Commits A simple set of scripts to enable a Git commit & push whenever entering a tracked directory true 2022-04-30T20:10:22.327Z git, maintanence markdown 2021-09-02T08:23:55.501Z

Automatic Git Commits

This techique is being phased out from Takahe - I didn't like it for home use. However, it is useful and may prove useful again - hence this page. {.is-warning}

Created for a non-Git savvy folk at work, the Takahe runs a pair of elegant Git auto commit scripts - the GitDaemon and the GitUpstreamer. After some modification, below is an outline on how these scripts work.

The first foothold is under the shell's profile - in our case, each user's ~/.zshrc file (you are using ohmyzsh, right?). If you look at the Environment Variables section at the bottom, you'll find the following:

### Environment Variables ###
export SCRIPTS="/home/shmick/Scripts"
source "$SCRIPTS/GitDaemon"

The Git Daemon script is a replacement that latches onto the cd command - it first executes normal cd and then finds out whether the directory is under Git.

The Git Upstreamer is what actually does the auto-commit - simply by quering the git command's output and committing to the set remote. This, of course, relies on a working set up remote.

You need to be aware of the following:

  • The scripts only run on directories with a file named .autocommit. Git is common, and I want to be in control of what goes upstream, to avoid awkward situations.
  • The scripts adds all files in the folder, and thus relies on a proper .gitignore file. If you had not explicitly ignored it - they will commit it!
  • The scripts' only toggle is via the shell profile. No shell profile - no scripts.

Under Git Automatic commits