Integrate Obsidian With Github
For Windows
Tools Used:
after install git make file call.bat
contains bash_git path
and the shell_script file
that we want to run it from windows using batch script
1cmd /c ""C:\Program Files\Git\bin\bash.exe" --login -i -- H:\myshell.sh"
{: lang=“batch”}
after that goto obsidian workspace folder create file .gitignore
1# To ignore files that could cause issues across different workspaces
2nano .gitignore
3# and set these 3 lines in
4.obsidian/cache
5.trash/
6.DS_Store
then create file .gitattributes
this file used to fix merge conflict automatically through keep both ours and theirs when conflict
1# Add a line to .gitattributes:
2*.md merge=union
initialize repo
1git init
2git add .
3git commit -m "init"
4git remote add origin https://github.com/USER/REPONAME.git
5# To permanently cache the credentials
6git config --global credential.helper store
7git push -u origin master
{: lang=“bash”}
Task Scheduler
make shell script file obsidian_git.sh
1# Making a new script to automate our repo management
2touch obsidian_git.sh
3chmod +x obsidian_git.sh
{: lang=“bash”}
obsidian_git.sh
1#!/usr/bin/env sh
2VAULT_PATH="/f/7S/IS/ZNotes/My_Plan_2020/Courses_Note_Offline"
3cd "$VAULT_PATH"
4
5# infinite loop repeat each 30 minutes
6while true
7do
8 # check internet connection before pull or push to avoit currupt script
9 out=$(curl -Is https://www.google.com | head -1)
10 if echo "$out" | grep -q "200"; then
11 git pull > /dev/null 2>&1
12 CHANGES_EXIST="$(git status --porcelain | wc -l)"
13
14 # check if $CHANGES_EXIST Not equal to zero that means there is some changes on obsidian files
15 if [ "$CHANGES_EXIST" -ne 0 ]; then
16
17 git pull > /dev/null 2>&1
18 git add .
19 git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")"
20 git push -q
21
22 fi
23
24 else
25 echo "Not Internet Connection..."
26 fi
27
28 sleep 30m
29
30done
{: lang=“shell”}
To run script automatic when system startup and hidden cmd console,
fist create vbs file run.vbs
and set these lines in
1Set WshShell = CreateObject("WScript.Shell")
2WshShell.Run chr(34) & "C:\Users\H\Documents\myObsidianWorkspace\call.bat" & Chr(34), 0
3Set WshShell = Nothing
{: lang=“vb”}
here should you change this path to your file path batch script file
that we create on top section
C:\Users\H\Documents\myObsidianWorkspace\call.bat
after that goto startup folder through shortcut keyboard Win+R
to open run window
type=> shell:startup
automatic will open startup folder,
last step copy run.vbs
file there
every time system start the script will be run
For Android
Tools Used:
generate token authentication for github to login with it on android automatic without authentication each time
Settings > Developer settings > Personal access token
open termux then run this command to access storage
termux-setup-storage
clone your repo with token authentication \
1cd storage/shared/
2git clone https://token_name:token_key@github.com/username/my_workspace
{: lang=“bash”}
change VAULT_Path
in obsidian_git.sh
with path your workspace in android
in termux run command pwd
to get current path then copy it and paste in obsidian_git.sh
to run script
bash obsidian_git.sh
will run automatic 😀 in background
for explore files and modify use obsidian app on android
that’s it everything done :)
References:
- https://git-scm.com/docs/git-credential-store
- https://git-scm.com/book/it/v2/Git-Tools-Credential-Storage
- https://www.tecmint.com/fix-git-user-credentials-for-https/
- https://stackoverflow.com/questions/11403407/git-asks-for-username-every-time-i-push
- ssh and http issues stackoverflow
- https://www.freecodecamp.org/news/how-to-fix-git-always-asking-for-user-credentials/