# How I Copy my Obsidian Files into my git Repository

> How I copy Obsidian notes into git so that I can author my notes in Obsidians and publish them to the web.

Source: https://curiouslychase.com/productivity/how-i-copy-my-obsidian-files-into-my-git-repository/

My workflow for frequently publishing content to my personal website with [Obsidian](https://curiouslychase.com/tools/obsidian/) relies on constantly fetching files from my Obsidian vault into my [git](https://curiouslychase.com/engineering/git/) repo and pushing it straight to GitHub, triggering a Vercel deployment.

# How It Works

I have a `yarn` script called `cpAndPush` that I run from the command line:
```shell
yarn cpAndPush
```

`cpAndPush` looks like this:

```shell
yarn prebuild:cpFiles && git add . && git commit -m 'update content' && git push origin HEAD
```

For this script to work, there are a few notes about my workflow:
- I work on `main` for my personal website, so doing this publishes to [curiouslychase.com](https://chaseadamsio.com)
- I keep my local repo clean if I'm not actively working on something. If I need to run this and have development changes, I'll run `git stash save -u -k "wip"` before running `yarn cpAndPush` so that my working tree is clean

`yarn prebuild:cpFiles` runs a script that:
- Recursively scans my Obsidian vault for `.md` and `.mdx` files
- Filters files by `status: published` or `status: draft` in frontmatter
- Excludes files with `fileClass: course-material`
- Routes files to different directories based on `fileClass`:
  - `fileClass: stack` → `content/stacks/`
  - `fileClass: prompt` → `content/prompts/`
  - Default → `content/posts/`
- Processes metadata:
  - Generates `slug` from filename using `slugify`
  - Sets `pubDate` from `liveDate` or file creation time
  - Sets `updatedDate` from `modified`, `pubDate`, or file modification time
  - Sets `type` based on `fileClass` (stack, prompt, or article)
- Extracts and copies embedded images:
  - Finds `` syntax
  - Copies images from vault's `01 - Meta/03 - Media/` to `public/img/notes/`
  - Also handles `cover` frontmatter field for cover images
