Personally I use a private Github repository for backing up my space. This is how I set this up.
Requirements
- A (free) Github account
- A private Github repository to keep your space files
Create a token
We will authenticate with Github via HTTPS and a personal access token. This is relatively safe and simple to setup.
Go to your Personal Access Tokens page, and Generate a new token (beta) scoped to your repository.
- Select a expiry date far in the future
- Select: “Only selected repositories” and select your private space repostiory.
- For permissions choose:
- Contents: Read & Write
Then generate the token. Save the token some place safe, you will need it later in a bit.
Get a shell
If you’re running SilverBullet directly on your machine, you can just cd into your space folder and use git from there (if it is installed, if not, install git first).
If you’re running inside of a docker container you need to get a shell into your container.
Using docker you can do this with docker exec. For instance, if your container is named silverbullet you can run:
docker exec -it silverbullet /bin/bash
By default you will be root. It’s important you perform the actions below as the same user as which silverbullet is running, to check which user this is, in the docker shell run:
ps aux
Look for a line that looks like this:
14 silverbu 0:00 /silverbullet
This will either list a user (second column) named silverbu (don’t mind that it’s truncated) or root. If it’s silverbu, su into this user before continuing:
su silverbullet
Configure the git repository
In your shell:
# Change to the space folder, in docker this is always /space
cd /space
# Initialize it as a git repo
git init
# Configure your name and email
git config user.name "Your Name"
git config user.email "[email protected]"
# Set rebasing to false (or true if you prefer)
git config pull.rebase false
# Add the Github repository you created as a remote, replace GITHUBTOKEN with the token you received earlier
git remote add origin https://[email protected]/username/repo.git
Empty repository
If you created a fresh Github repository with no content yet, you can do the following:
# Set the branch to main
git branch -m main
# Configure the default upstream
git branch --set-upstream-to=origin/main main
# Add all existing files
git add *.md
# Commit the first version
git commit -m "Initial commit"
# Push the first version
git push origin main
Existing content
If your repository already has content, first clean out the auto generated files (index.md and SETTING.md), then checkout the remote branch:
# Fetch all branches from the remote repostiroy
git fetch
# Clean out the auto generated pages
rm index.md SETTINGS.md
# Checkout your main branch from the repository
git checkout main
Installing the Git library
Open the SilverBullet Library Manager with the Library: Manager command, look for the “Git” library, and click “Install” to install it.
This will give you some useful Git: * commands. Click on the link for the Git library in the “Installed Libraries” section for more information on how to use the integration.
Enjoy!