7.6 KiB
Resources:
- Follow the instructions here and document as you go:
- apparently the extension Obsidian-Git already does this in an easier way now
- So this is how you push it to your gitlab
- Refer to the Git page on here for more shortcuts.
Syncing my Obsidian: The Steps I took
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.
OLD METHOD: Making a Repo in GDrive
- **Find your Google Drive location and copy the directory path.
pwd | pbcopy
- Go to your local projects folder and
git init
there locally.
mkdir gitlab_sync
cd gitlab_sync
git init
git branch -m main
#renamed branch to main insted of master
#less typing xD
- Then create a bare clone copy into your copied google drive location.
git clone --bare . ~user/Google\ Drive/My\ Drive/folder/location.git
- Then go ahead and make a new remote using this git path inside your local directory.
git remote add NameOfRemote ~user/Google\ Drive/My\ Drive/folder/location.git
- Make some changes to your git repository by adding files and commit those changes.
**git** add LICENSE.md
**git** commit -m 'Initial sync version'
- Then I pushed the changes to the remote google drive location.
git push -u origin main
Pushing to Gitlab
- Next, I added the (SSH) remote of the gitlab server to upload to as well.
git remote add NameofRemote git@gitblah.com:user/repo.git
- I then created another branch for the upload sync to take place.
git branch AnotherBranch
git checkout AnotherBranch #switch into it
-
Then follow the instructions outlined on this article. 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
-
Then do a git remote by
git remote add REMOTE_NAME PATH_TO_GOOGLE_DRIVE_SYNC_FOLDER/ANY_SUBFOLDER_PATH/PROJECT_NAME.git
-
Add files to stage for commit and commit a message.
git add .
git commit -m "an update message here"
- Lastly, push the changes onto your quantum programming repo.
git push -u origin main
Voila! You should see the changes now over here. Or wherever you decided to set up host the git remote server on.
CURRENT METHOD: Syncing via Gitea Server
This can be done locally or via Google Drive. However, I will be using Linode to host Gitea to host my obsidian and all my repos locally. Go to the folder on your laptop that you'd like to start the git syncing your Obsidian Vault at and run:
git init
This sets up the git process. Next you have to clone the existing repository and pull .
git clone http:/giteaurlhere.git
And then pull the existing information from the repo.
git pull
git add .
git commit -m "some message"
git push -u origin main
Then Open Your Obsidian Vault there. You are now ready to have your changes synced from Obsidian to Git.
git add .
git commit -q -m "$(date)"
Push your changes once more after you have opened your vault there.
git add .
git commit - m "some message"
For Linux: Sync the Obsidian vault very few minutes with this script via cron
:
#!/usr/bin/env sh
# ^^^^^^^^^^^^^^^ This says find the first instance of a sh (shell)
# binary and use that shell to execute these commands.
# There is little to no complexity here and no bashisms so it
# should work just fine on most systems and instances of shells
# (bash, zsh, sh, etc.)
ZK_PATH="PATH TO YOUR VAULT"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ We are assigning the variable `ZK_PATH`
# with the (maybe) long string to our vault's location (mine is super
# long so this makes the final command look cleaner,
# it's unnecessary if you care)
cd "$ZK_PATH"
# ^^^^^^^^^^^ cd: Change Directory to your vault's location
git pull
# ^^^^^^ So if any changes occurred remotely or on another machine
# your local machine knows to pull those changes down instead of
# having to wait for a local change to run the script
CHANGES_EXIST="$(git status --porcelain | wc -l)"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ we are assigning
# a value to the variable `CHANGES_EXIST`, the value is the output
# of `git add --porcelain` which outputs a simple list of just the
# changed files and then the output is piped into the `wc` utility
# which is "word count" but with the `-l` flag it will count lines.
# basically, it says how many total files have been modified.
# if there are no changes the output is 0
if [ "$CHANGES_EXIST" -eq 0 ]; then
exit 0
fi
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The whole if block is saying
# in plain english: if there are no changes (CHANGES_EXIST = 0)
# then exit with no error code `exit 0` if there are changes,
# then continue on with the script
git pull
# ^^^^^^ git pull: this will look at your repo and say "any changes?"
# if there are they will be brought down and applied to your local machine
# In the context of a team environment, a more robust approach is needed
# as this workflow doesnt factor in branches, merge conflicts, etc
# but if you leave your home machine, do work on the work machine,
# push to the remote repo before you return to the home machine, then
# you can just get the latest changes applied to the home machine and
# continue on like normal
git add .
# ^^^^^^^ git add. = add all current changes in the repo no
# matter the level of nested folders/files
git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# git commit -q -m: this says we are committing changes to
# our repo, -q says BE QUIET no output prints to terminal
# if ran manually, -m defines a message for the commit log
# the -m message is "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")" this
# runs the command date with the formatting arguments for a
# date in YYYY-MM-DD HH-MM-SS format as your commit message
git push -q
# ^^^^^^^^^ git push -q: push the changes to github and
# BE QUIET about it The semicolons between commands are
# just saying run each command and then run the subsequent
# command, they're just separators
Save
For Mac: Sync Obsidian vault via Launchd by writing a plist script:
- Lastly but not leastly, I stumbled upon Perlite in my search for obsidian sync. ! The sample view of Perlite extension.
Another site that you can render Obsidian in: !