Syncing your obsidian to version control is probably the most efficient way to host your information locally without relying on a cloud provider for unlimited storage. View the process below to see how I got started.
My Obsidian files are all stored within Google Drive. So in order to maintain sync while still preserving cloud storage space, I used a few different steps than the guides, and well really it was a culmination of it all.
This can be done locally or via Google Drive. However, I will be using **[Linode](obsidian://open?vault=enter&file=Coding%20Tips%20(Classical)%2FTerminal%20Tips%2FGUIs%2FInternet%2FServers%2FCloud%20Servers%2FLinode)** to host [Gitea](obsidian://open?vault=enter&file=Coding%20Tips%20(Classical)%2FTerminal%20Tips%2FGUIs%2FInternet%2FRepos%2FGitea) to host my obsidian and all my repos locally.
But basically this is the self-hosted information flow: A Sketch
##### 3. Syncing Your Vault to Push every few minutes
So this is all great and all, you can now push and pull to a remote server that you own! However, it is a bit annoying to have to do the same terminal commands of git pull, add, commit, push, blah blah dsjkhfalfhk. It can get repetitive. So what do we do? We make a script that can take care of this automatically for us.
###### *For Linux:* Sync the Obsidian vault very few minutes with this script via `cron`:
So the goal here is to put a launchd .plist into that so that your Mac knows to trigger a LaunchDaemon upon a certain trigger.
2. First, however we need to make a bash script that does that syncing itself. This can be done by navigating to `~/.local/bin` and create a shell script by:
```
touch zk_sync
chmod +x zk_sync
```
*Separately:* Also make sure to copy the absolute path of your vault as that will be the environment variable that you will input into `ZK_PATH` to ensure that it still works. You can obtain the path by:
```
> pwd
#output
> /Users/shwethajayaraj/Google Drive/My Drive/RESOURCES (Research - my notebook)/collabtestdir/Notepad
```
If there are spaces in your working directory just make sure that you put in wrapped double quotation marks.
3. What are the actual contents of the shell script though that have to be done?? Well, go ahead and `vim` into the `zk_sync` file and paste the following in:
4. Now it is time to submit this to the `launchd` scheduler. Navigate to `~/Library/LaunchAgents` as this is where you will be dropping your .plist file.
8. I then created another branch for the upload sync to take place.
```
git branch AnotherBranch
git checkout AnotherBranch #switch into it
```
9.
10. Then follow the instructions [outlined on this article](https://techstreams.medium.com/git-google-drive-simple-git-host-3a84db4fc1fd). Basically you then create a git clone of it in your new directory by `git clone --bare . PATH_TO_GOOGLE_DRIVE_SYNC_FOLDER/ANY_SUBFOLDER_PATH/PROJECT_NAME.git`
11. Then do a git remote by `git remote add REMOTE_NAME PATH_TO_GOOGLE_DRIVE_SYNC_FOLDER/ANY_SUBFOLDER_PATH/PROJECT_NAME.git`
12. Add files to stage for commit and commit a message.
13. Lastly, push the changes onto your quantum programming repo.
```
git push -u origin main
```
Voila! You should see the changes now [over here](https://gitlab.com/shwetha729/quantum-programming). Or wherever you decided to set up host the git remote server on.
- Follow the instructions [here](https://medium.com/analytics-vidhya/how-i-put-my-mind-under-version-control-24caea37b8a5) and document as you go:
- on [Cron]( https://osxdaily.com/2020/04/27/fix-cron-permissions-macos-full-disk-access/):
- *UPDATE*: crontab is deprecated for MacOS so the sync option given will not work.
- the best next alternative is then to use [launchd](obsidian://open?vault=enter&file=Coding%20Tips%20(Classical)%2FTerminal%20Tips%2FShells%2FComputers%20(operating%20system)%2FApple%20Macbook%2FLaunchd) or keyboard scheduler as described through this youtube video.
- Refer back to [plists](obsidian://open?vault=Coding%20Tips&file=Computers%2FMac%20OS%20X%2FBBEdit%2Fplist) for a better understanding of implementation and usage.
- apparently the extension [Obsidian-Git](https://github.com/denolehov/obsidian-git/wiki/Installation#existing-repo) already does this in an easier way now
- So this is how you [push it to your gitlab](https://about.gitlab.com/blog/2022/03/15/publishing-obsidian-notes-with-gitlab-pages/)
- Refer to the [Git page](obsidian://open?vault=Obsidian&file=Coding%20Tips%2FComputers%2FTerminal%20Tips%2FGit) on here for more shortcuts.
- This page exists now showing o[ne way to setup gitea with Obsidian](https://webuxlab.com/en/projects/gitea-obsidian)