Setting up Git with obsidian cross mac platform
Back up your obsidian folder using git
On your laptop (main device)
cd /path/to/obsidian/yourVault
git init
git status
git add .
git commit -m "first commit"
gh repo create
# Existing repo .
git push
Then begin on your phone
using A-shell and shortcuts
On Iphone, one of the most powerful things you can do is use a shell lmao. God I love the shell.
Download A-shell
A shell has the ability to pickFolder, which lets you move and shell into different applications. its fucking perfect
create a personal access token in your shell, fuck your ssh keygens, i have always had problems with them and pats just work.
since a shell uses pkg to install git, you will want to run
pkg install git
Using git on mobile
let's clone your repository, we have to use your personal access token by paste the first time:
using https
git clone https://github.com/user-name/your-repo.git
now you might have to use your email and pass
.git/config
then: you can set up your config file. it should be found in:
your-repo/.git/config
which you can edit directly
[user]
name = your-name
email = yoruoe@uoyfaso.com
password = ghppersonalaccesstoken
...
lg2 config
or you can fuck around with the lg2 config ways. I would just run its easier
lg2 config user.name your-name
lg2 config user.email your-email@email.com
lg2 config user.password yourpersonalaccesstoken
now lets not add your pat to the world wide web. So again on your device:
cd your-repo
vim .gitignore
.gitignore
and in your /.gitignore so you dont leak your pat
.gitignore
.git/config
now you can try git pulling and see if it works.! on mac you can even use shortcuts
using shortcuts
You would have to use the a-shell shortcuts, using execute command
For this because of how apps and sandboxing is set up, you will have to start out your thing with a pickFolder
so essentially a command that would use executeCommand
pickFolder | git pull
or your combo for pushing. I would do
pickFolder | git pull | git add . | git commit -m "iphone push" | git push
you can add it to your home page and you are set!
lmk if you have any issues
Make sure you have a tight fucking leash on your
.gitignore file
Your .gitignore becomes insanely important. because fucking DUH
here is mine, take from it what you will. :
.git/config
.gitignore
.obsidian/workspace.json
.obsidian/workspace-mobile.json
/Gabriel's Brain/pubs
!/Gabriel's Brain/pubs/
/Gabriel's Brain/pubs/**
the config file
The config file is important to git ignore because you will want to set up your git in different ways on each device. As stated earlier in #.git/config this is where your user data will go. Let's not leak that
.gitignore
You know why. check it: #.gitignore file
workspace files
The .obsidian directory seems very helpful. you need almost all of the things in there, because they have the plugins that make your app work. however it also saves the way you left your obsidian before moving on. so let's make sure that you ignore that too. Both the normal one and the one on mobile
my pubs. This is for my symbolic links
I dont even think this shit works tbh. its just an artifact atp
Some Specific problems:
Using symbolic links
Symbolic links always pose some sort of issue because the files just, ARENT THERE so how do I deal with this. I know how I want to deal with it, so I write pseudocode. I don't know how I'll do it so I ask Claude. Theres always so much to do.
How I want to deal with this is by using a git hook. I use a pre-commit hook that deletes the symlink and then copies all the files over, then adds the files then deletes the symlink. This is the only way I want to conduct this from the computer, on all other devices I don't mind because this will be the only copy on those devices anyways.
So! here is my bash code that you have to make executable like in any other type of scripting.
you'll want to save this in your
Here is my single symlink thing. I've also included another copy that should deal with these things more generally, but I haven't tested it. Thats a problem for future gab.
.git/hooks/pre-commit
Mine, that works
#!/bin/bash
PUBS_SOURCE="/Users/gabrielhusain/Documents/Berkeley/pubs"
PUBS_DEST="./Gabriel's Brain/pubs"
# Store if symlink existed
was_symlink=0
[ -L "$PUBS_DEST" ] && was_symlink=1
# Remove symlink if it exists
[ -L "$PUBS_DEST" ] && rm "$PUBS_DEST"
# Copy files
mkdir -p "$PUBS_DEST"
rsync -av --delete "$PUBS_SOURCE/" "$PUBS_DEST/"
# Force add the contents
git add -f "$PUBS_DEST/"
# Restore symlink if it existed
if [ $was_symlink -eq 1 ]; then
rm -rf "$PUBS_DEST"
ln -s "$PUBS_SOURCE" "$PUBS_DEST"
fi
Generalized
Here is the generalized version:
#!/bin/bash
# Store all symlinks and their targets
declare -A symlinks
while IFS= read -r -d '' link; do
if [ -L "$link" ]; then
target=$(readlink "$link")
symlinks["$link"]="$target"
fi
done < <(find . -type l -print0)
# Process each symlink
for link in "${!symlinks[@]}"; do
target="${symlinks[$link]}"
# Remove symlink
rm "$link"
# Create directory and copy contents
mkdir -p "$link"
rsync -av --delete "$target/" "$link/"
# Force add the contents
git add -f "$link/"
# Restore symlink
rm -rf "$link"
ln -s "$target" "$link"
done
Ensure that after this that you run
chmod +x .git/hooks/pre-commit
Now that you will be essentially find all sym links, delete all symlinks list them up, and then create them