Storing an Obsidian vault on GitHub

Technology
Author

Iury Simoes-Sousa

Published

February 21, 2023

Introduction

In this tutorial, you will learn how to integrate Obsidian, a popular note-taking app, with GitHub, a web-based version control system. By doing this, you can store your notes on GitHub and have a version history that allows you to revert to previous versions if needed. In addition, you can collaborate with others by sharing your notes with them and even work on them simultaneously. This tutorial assumes that you are familiar with Obsidian and GitHub.

Why integrate Obsidian with GitHub?

Recently I started using Obsidian to organize my notes. What I love most about this software is that everything is in Markdown, which not only makes it easy to access and port to other tools, but I am also free to make my own code in Python or other languages to interact with the notes. If you are curious about Obsidian, there are several tutorials on the internet for you to learn how to use it.

Obsidian is a great note-taking app that uses Markdown, making it easy to access and port your notes to other tools. However, Obsidian charges a fee for synchronization between different devices. One way to work around this is to use a storage service like Dropbox, Google Drive, or OneDrive. However, if you want to mix code and tutorials with your notes or are concerned about different versions of your notes, integrating with GitHub is a good alternative. GitHub allows you to store your notes on its platform and also provides version control, which means you can keep track of all changes made to your notes.

Linux

  1. Create a new repository on GitHub

The first step is to create an empty repository on GitHub. Go to GitHub and create a new repository.

  1. Clone the repository to your local machine

Once you have created the repository on GitHub, you need to clone it to your local machine. Open your terminal and navigate to the directory where you want to place your Obsidian vault. Then, run the following command:

git clone <repository URL>
  1. Copy your Obsidian vault to the repository

If you already have an Obsidian vault set up, you can copy all files and folders to the local repository. You can do this by running the following command:

cp -r <path/to/existing/vault> <path/to/repository>

If you do not have an Obsidian vault set up yet, you can create one at the repository folder.

  1. Sync your local repository with GitHub

Once you have copied your Obsidian vault to the local repository, you need to sync it with GitHub. Run the following commands:

cd <path/to/repository>
git add .
git commit -m "Initial commit"
git push

These commands will add all the files in the repository to the staging area, create a commit with the message “Initial commit,” and push the changes to the main branch on GitHub.

  1. Set up automatic syncing with cron

Now that your Obsidian vault is in the repository, you need to set up automatic syncing with cron. Cron is a UNIX utility that allows you to schedule tasks to run at specific intervals. If you have more questions on how to install and configure cron, you can follow this tutorial. To set up cron, run the following command:

crontab -e

This will open the crontab file in the default text editor. Add the following line to the file:

*/5 * * * * cd <path/to/repository> && git pull && git add . && git commit -m "Automatic update" && git push

This command will sync your local repository with the GitHub repository every 5 minutes. You can change the interval by replacing the “/5” with a different value. For example, “/10” would sync every 10 minutes, and “0 * * * *” would sync every hour.

  1. Verify that everything is working

To verify that your Obsidian vault you can make some changes on a note and wait cron to run the command and check it updated on GitHub.

Windows

If you’re a Windows user, you can do it using Windows Subsystem for Linux (WSL).

  1. Choose a place on a Windows folder to put the vault
  2. Access the folder through WSL (you can access Windows files by /mnt/), clone the Git repository by running the following command in the WSL terminal:
git clone <repository URL>
  1. Change the default editor for visudo to vim. This is a personal preference, but many developers prefer vim over nano. To do this, run the following command in the WSL terminal:
sudo update-alternatives --config editor
  1. Select vim.basic from the list of editors.

  2. Grant sudo access to run cron without a password by adding the following line to the end of the visudo file:

# run cron start with no password
%sudo ALL=NOPASSWD: /usr/sbin/service cron start
  1. Save the changes and exit the visudo file.

  2. Open the .bashrc file by running the following command in the WSL terminal:

vim ~/.bashrc
  1. Add the following line at the end of the .bashrc file to start cron automatically:
sudo service cron start
  1. Create a cron job that updates the Git vault every 5 minutes. To do this, run the following command in the WSL terminal:

  2. Now we can add a cron job to update the vault every 5 minutes. Run crontab -e and add the following command at the end of the file

crontab -e

Then add the following line at the end of the file:

*/5 * * * * cd <path/to/repository> && git pull && git add --all && git commit -m "Automatic backup" && git push 
  1. Save the changes and exit the file.

  2. f you want to start WSL automatically when you log in to your Windows account, you can create a scheduled task using the Windows Task Scheduler:

    1. Open the Task Scheduler app on your Windows system.
    2. Click on “Create Basic Task” and follow the wizard to create a new task. 3)Set the trigger to “When I log on”.
    3. Set the action to “Start a Program” and select the path to WSL. For example:
    C:\Windows\System32\wsl.exe