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
cmd /c ""C:\Program Files\Git\bin\bash.exe" --login -i -- H:\myshell.sh"
after that goto obsidian workspace folder create file .gitignore
# To ignore files that could cause issues across different workspaces
nano .gitignore
# and set these 3 lines in
.obsidian/cache
.trash/
.DS_Store
then create file .gitattributes
this file used to fix merge conflict automatically through keep both ours and theirs when conflict
# Add a line to .gitattributes:
*.md merge=union
initialize repo
git init
git add .
git commit -m "init"
git remote add origin https://github.com/USER/REPONAME.git
# To permanently cache the credentials
git config --global credential.helper store
git push -u origin master
Task Scheduler
make shell script file obsidian_git.sh
# Making a new script to automate our repo management
touch obsidian_git.sh
chmod +x obsidian_git.sh
obsidian_git.sh
#!/usr/bin/env sh
VAULT_PATH="/f/7S/IS/ZNotes/My_Plan_2020/Courses_Note_Offline"
cd "$VAULT_PATH"
# infinite loop repeat each 30 minutes
while true
do
# check internet connection before pull or push to avoit currupt script
out=$(curl -Is https://www.google.com | head -1)
if echo "$out" | grep -q "200"; then
git pull > /dev/null 2>&1
CHANGES_EXIST="$(git status --porcelain | wc -l)"
# check if $CHANGES_EXIST Not equal to zero that means there is some changes on obsidian files
if [ "$CHANGES_EXIST" -ne 0 ]; then
git pull > /dev/null 2>&1
git add .
git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")"
git push -q
fi
else
echo "Not Internet Connection..."
fi
sleep 30m
done
To run script automatic when system startup and hidden cmd console,
fist create vbs file run.vbs
and set these lines in
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Users\H\Documents\myObsidianWorkspace\call.bat" & Chr(34), 0
Set WshShell = Nothing
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
cd storage/shared/
git clone https://token_name:token_key@github.com/username/my_workspace
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/