git-auto
git-auto copied to clipboard
Git Commit Hook Alternative
I just wanted to post a quick alternative to git-auto
using a git post-commit
hook and some gotchas I ran into while getting this set up. I like this approach because it ensures every commit is immediately pushed.
Creating post-commit
hook
- Ensure your logseq database is a git repository. This usually entails running
git init
in the root of the logseq directory. - Check "Enable Git auto commit" in the Logseq version control settings.
- Create the file
.git/hooks/post-commit
relative to the root of the logseq repository with the following contents:#!/bin/bash git push
Potential Gotchas
-
On macOS, I usually use the
osxkeychain
for authentication using a "personal access token". This, for some reason didn't work out well and kept giving me the following error:fatal: could not read Username for 'https://github.com': Device not configured
. I ensured that the script was being run as personal account, notroot
, but this didn't fix the issue. The easiest solution was to switch to using thegit-credential-manager
(GCM).# check if current credential.helper is osxkeychain ❯ git config credential.helper osxkeychain # clear osxkeychain password ❯ git credential-osxkeychain erase host=github.com protocol=https > [Press Return] # install latest git and git credential manager (GCM) from homebrew ❯ brew install git ❯ brew tap microsoft/git ❯ brew install --cask git-credential-manager-core # verify cask installation has automatically updated the credential.helper ❯ git config credential.helper /usr/local/share/gcm-core/git-credential-manager-core # attempt to git push, will bring up a pop-up establishing authentication git push
-
For some reason, I was unable to change the hashbang for the post-commit hook. It seems to always use the system bash installed at
/bin/bash
(for me, version 3.2.57) even if I explicitly changed the hashbang to homebrew installed bash via#!/opt/homebrew/bin/bash
. This means you can't use newer bash features likemycmd &>> /tmp/mylog
etc.This longer script helped me debug all of these issues:
#!/bin/bash mkdir -p /tmp/logseq/ timestamp=$(date +"%s") filepath="/tmp/logseq/$timestamp" touch $filepath echo "attepmting push" >> $filepath echo "current directory: $(pwd)" >> $filepath echo "bash version: $(bash --version)" >> $filepath echo "whoami: $(whoami)" >> $filepath git remote -v >> $filepath 2>&1 git push >> $filepath 2>&1
Hope this helps!
Nice alternative. I was having issues getting git-auto to work on Windows.
For those on windows the contents of .git/hooks/post-commit
should be
#!/bin/sh
git push