Skip to content

Instantly share code, notes, and snippets.

@ivanskodje
Last active October 7, 2022 18:36
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 ivanskodje/eb370b4ac612a95de36834ecebe57b99 to your computer and use it in GitHub Desktop.
Save ivanskodje/eb370b4ac612a95de36834ecebe57b99 to your computer and use it in GitHub Desktop.
Git Sync Script
#!/usr/bin/env sh
# Purpose: For automating sync between Obsidian.md Vault and Git
# Modified script, not original work. Removed a lot of comments.
#
# You can find the original script here (thank you for making it):
# https://gist.githubusercontent.com/lucidhacker/0d6ea6308997921a5f810be10a48a498/raw/386fd5c640282daeaa3c9c5b7f4e875511c2946c/zk_sync.sh
# If you are using android+termux,
# replace the first line with this: #!/data/data/com.termux/files/usr/bin/bash
# If you are using android+termux, and you have run "termux-setup-storage" on termux to setup symlinks,
# the path structure looks something like: "/data/data/com.termux/files/storage/shared/documents/your-vault-here"
# CHANGE PATH
VAULT_PATH="/FULL/PATH/TO/YOUR/VAULT"
# Check for changes
cd "$VAULT_PATH"
git pull
CHANGES_EXIST="$(git status --porcelain | wc -l)"
if [ "$CHANGES_EXIST" -eq 0 ]; then
exit 0
fi
# Perform Sync
git pull
git add .
git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")"
git push -q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment