Syncing with git

Enter the right folder

pwd //显示当前文件夹路径(print working directory)
ls //**列出当前文件夹里的内容**(list directory contents
../   //回到上一层目录

My path

cd "/Users/jz/Library/Mobile Documents/iCloud~md~obsidian/Documents/plugin-use-CN"

Sync to GitHub

  1. Create a new repo on GitHub — don’t check README / .gitignore (we create those locally) — and get the repo’s SSH URL.
  2. Enter your local project directory Initialize the repo
git init

Create .gitignore

touch .gitignore

Common things to ignore for an Obsidian plugin

node_modules/
dist/
.obsidian/
.DS_Store
  1. First commit Check the current status
git status

Stage all files

git add .

Commit

git commit -m "init: first commit"
  1. Push the local code to GitHub Bind the remote repo
git remote add origin ssh-url

Double-check (optional)

git remote -v

Push to GitHub Rename the local branch (GitHub’s default branch is main; rename your local branch to main so the sync works — you can check the name with git branch)

git branch -M main

Push the branch to GitHub and set up tracking

git push -u origin main
  1. Day-to-day push flow Stage
git add .

Commit message

git commit -m 

Sync

git push

Force-overwrite the remote repo

git push -f
  1. Commit message conventions
feat: 新功能
fix: 修 bug
refactor: 重构
docs: 文档
style: 只改格式

Rolling back a git version

View the commit history

git log --oneline

Roll back HEAD while keeping your working-tree changes

git reset --soft <commit_hash>

Undo the rollback Find the commit you had before the rollback

git reflog

Point HEAD back to the original commit

git reset --soft original-hash

Don’t roll back — just dig out the old code

Check out an entire old version into some temporary place

git show d31e499:src/ui/SidebarOverviewView.ts -- “/Users/jz/Library/Mobile Documents/iCloud~md~obsidian/Documents/all-in/.obsidian/plugins/learning-system/src”

Submodules

Say the plugin lives in repo A, and repo B needs to reuse A’s plugin. Set this up in repo B:

git submodule update --remote
git commit -am "update a-plugin"
git clone --recurse-submodules +A仓库的shh

Subsequent sync flow

git submodule update --remote
git commit -am "update learning-system submodule"

If a plugin with the same name already exists locally but isn’t a submodule

rm -rf .obsidian/plugins/learning-system
git submodule add [email protected]:jady21a/obsidian-learning-system.git .obsidian/plugins/learning-system
git commit -m "add learning-system submodule under .obsidian/plugins"
 

Verify it worked

git submodule status