Skip to content

Instantly share code, notes, and snippets.

Last active Jan 16, 2023
What would you like to do?
Iteratively loop through all files in DIR and add-commit-push them to REPO.
This script should sit in your obsidian vault.
from pathlib import Path
from git import Repo
import os
DIR = '/Users/eugene/obsidian-vault/assets'
REPO = Repo('.')
for i, path in enumerate(Path(DIR).iterdir()):
file_size = int(os.stat(path).st_size / 1024)
print(f'file {i}: {str(path).split("/")[-1]} ({file_size} kb)')
if file_size < 1024:
commit_msg = f'Add {str(path).split("/")[-1]}'
REPO.index.add(str(path)) # Add
REPO.index.commit(commit_msg) # Commit
origin = REPO.remote('origin')
origin.push() # Push
print(f'Skipping file {i}: {str(path).split("/")[-1]} ({file_size} kb)')
f = open("skipped-files.txt", "a")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment