banner
YZ

周周的Wiki

种一棵树最好的时间是十年前,其次是现在。
zhihu
github
csdn

Obsidian Note Sync Github Repository Workflow

Workflow for backing up this knowledge base to a Github repository.

Preparation#

Git Installation#

  1. Go to the Git official website and download and install Git.
    Pasted image 20240825103341
    Install with the default selected configurations.
  2. Verify if Git is installed successfully.
    Open the Cmd command line window by pressing Win + R and enter: git help. If there is output, it means Git is installed successfully.
    Pasted image 20240825104636

Prepare Github Account and Remote Repository#

  1. Go to the Github official website and register and log in to a Github account.
  2. Click the "+" button in the upper right corner to create a repository.
    Pasted image 20240825105940
    Fill in the repository information.
    Pasted image 20240825111133

SSH Key Configuration#

  1. First, configure your Github account locally.
    Open Git Bash and enter the following commands:

git config --global user.name "username"
git config --global user.email "email"

Pasted image 20240825112031
2. Generate SSH key files.
Continue entering the command:

ssh-keygen -t rsa -C "email"

Press Enter three times according to the prompts, and the following content will appear, indicating that the SSH file is created successfully.
Pasted image 20240825112610

  1. Configure the public key id_rsa.pub to your Github account.

Find the .ssh\id_rsa.pub file created in the previous step, open it with Notepad, copy the content inside, open the Github homepage, go to Settings -> SSH and GPG keys -> New SSH key:
Pasted image 20240825113814

  1. Verify if the local connection to Github through SSH is successful.

Enter the command in Git Bash: ssh -T [email protected], and enter "yes" as prompted. If the following content is displayed, it means the SSH configuration is successful.
Pasted image 20240825120417

Install Git Plugin in Obsidian#

In the Obsidian note-taking software, go to Settings -> Third-party plugins -> Community plugins, click on "Browse" and search for "Git", click on "Install" and enable it.
Pasted image 20240825121804

If the Git Control View does not appear in the Obsidian sidebar, press Ctrl + P, search for and click on Obsidian Git: Open Source Control View to make it appear.
Pasted image 20240825123134

The top buttons of the plugin correspond to some commonly used Git operations:

  1. Backup: Backup, commit all changes, and perform a push.
  2. Commit: Confirm the commit, but do not push.
  3. Stage all: Store the current changes.
  4. Unstage all: Unstage the changes.
  5. Push: Push to the remote, can be understood as pushing to Github.
  6. Pull: Pull from the remote to the local, can be understood as pulling the latest data from Github to the local.
  7. Change Layout: Change the layout of the files below.
  8. Refresh: Refresh the current file changes.

Git Plugin Configuration#

  1. Open Obsidian, go to Settings -> Third-party plugins -> Git.
    Pasted image 20240825144403.png

Configure backup interval, automatic pull, and other options as needed. Every time you make changes, Git will automatically back up according to the interval you set, or you can manually back up by clicking the Git icon on the toolbar.

Pushing the Knowledge Base Notes to the Remote Repository#

  1. First, copy your SSH credentials from Github.
    Pasted image 20240825135056

  2. Right-click on the directory where the knowledge base is located and select "Open Git Bash here".
    Pasted image 20240825135219

  3. Enter the following commands in the terminal:

git init // Initialize Git
git add --all // Add all files in the current directory
git commit -m "first commit" // Commit the changes
git remote add origin [email protected]/ZhouYingWiki.git // Replace with your own repository
git push -u origin master // Push to the remote repository branch "master"

If the following information is displayed, it means the push is successful.
Pasted image 20240825142347

Afterwards, you can directly use the Git plugin in the Obsidian note-taking software to push and sync.

How to delete mistakenly synchronized files or ignore certain files?#

Delete directories and files on the Git repository#

  1. As you can see, I mistakenly pushed .obsidian and 欢迎.md to the repository. Now I want to delete them from the remote repository.
    Pasted image 20240825150357.png
  • Delete remote directory
    Use the command: ==git rm -r --cached .obsidian==
  • Delete remote file
    Use the command: ==git rm 欢迎.md --cached==
  1. Commit the changes and push
    git commit:
    Pasted image 20240825152231.png

git push:
Pasted image 20240825152349.png

You can see that the related files and directories have been deleted from the repository:
Pasted image 20240825152706.png

Ignore directories and files that do not need to be pushed#

  1. Create a new text file in the note directory, rename it to ==.gitignore==, and add the directories and files to be ignored, such as: .obsidian
    Other files need to be preceded by a slash "/" to be recognized.
    Pasted image 20240825154139.png

This way, these ignored files will not be uploaded in your future commits and pushes.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.