Skip to content

Instantly share code, notes, and snippets.

@bukanspot
Last active March 20, 2024 09:30
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 bukanspot/2677e31f17a20fb11241ae583798bfb0 to your computer and use it in GitHub Desktop.
Save bukanspot/2677e31f17a20fb11241ae583798bfb0 to your computer and use it in GitHub Desktop.
Automatically push directory to GitHub using cronjob
#!/usr/bin/env sh
directory=<working-directory>
cd $directory
git pull origin main -q
result=$(git status --porcelain | wc -l)
if [[ $result -eq 0 ]] ; then
exit 0
fi
git add .; git commit -q -m "$(date +"%c")"; git push origin main -q
@bukanspot
Copy link
Author

bukanspot commented Dec 11, 2022

This is example to push obsidian directory to GitHub

For first

  • Make sure you make obsidian directory as repository and push to github.
  • Make sure you have install cron or cronie and enable service on reboot.

Lets setup

Create or go to directory ~/.local/bin

sudo mkdir ~/.local/bin/ ; cd ~/.local/bin/

Create file script with name pusher-obsidian.sh

touch pusher-obsidian.sh

Copy and paste script and put here (modify the script to your needs). Change <working-directory> with your obsidian directory

nano pusher-obsidian.sh

Use a cron job to run automatically

crontab -e

And put the code

@reboot /bin/sleep 120 ;  ~/.local/bin/pusher-obsidian.sh

Now, when you add new note in obsidian, your note from obsidian will automatically push to GitHub when computer reboot or start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment