Workflow for backing up this knowledge base to a Github repository.
Preparation#
Git Installation#
- Go to the Git official website and download and install Git.
Install with the default selected configurations. - 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.
Prepare Github Account and Remote Repository#
- Go to the Github official website and register and log in to a Github account.
- Click the "+" button in the upper right corner to create a repository.
Fill in the repository information.
SSH Key Configuration#
- 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"
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.
- 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:
- 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.
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.
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.
The top buttons of the plugin correspond to some commonly used Git operations:
- Backup: Backup, commit all changes, and perform a push.
- Commit: Confirm the commit, but do not push.
- Stage all: Store the current changes.
- Unstage all: Unstage the changes.
- Push: Push to the remote, can be understood as pushing to Github.
- Pull: Pull from the remote to the local, can be understood as pulling the latest data from Github to the local.
- Change Layout: Change the layout of the files below.
- Refresh: Refresh the current file changes.
Git Plugin Configuration#
- Open Obsidian, go to Settings -> Third-party plugins -> Git.
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#
-
First, copy your SSH credentials from Github.
-
Right-click on the directory where the knowledge base is located and select "Open Git Bash here".
-
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.
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#
- As you can see, I mistakenly pushed .obsidian and 欢迎.md to the repository. Now I want to delete them from the remote repository.
- Delete remote directory
Use the command: ==git rm -r --cached .obsidian== - Delete remote file
Use the command: ==git rm 欢迎.md --cached==
- Commit the changes and push
git commit:
git push:
You can see that the related files and directories have been deleted from the repository:
Ignore directories and files that do not need to be pushed#
- 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.
This way, these ignored files will not be uploaded in your future commits and pushes.