Backup your space to Github

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!

7 Likes

I deployed SilverBullet to fly.io then I used the git plug to backup my space to Github. The problem is that I can sync it manually but the autoSync and autoCommit feature seem not working. Is that a limitation of fly.io or did I do something wrong?

I think it works only if you keep your fly machine active. Fly stops machines after a few minutes of inactivity, and then the auto commit stuff also won’t run.

1 Like

I worked around it by using space-script to call git.syncCommand whenever a page is saved

1 Like

I also assume it’s a good idea to include a .gitignore with the below contents. @zef, could you confirm this is correct and if any others are suggested?

.silverbullet.db*
_plug/
Library/

I noticed Library/Personal/* is recommended for storing templates/library edits, so this should be included in git, correct?

1 Like

Yes, this is roughly the .gitignore I use as well, except that I just commit the Library folder as well because… why not :slight_smile: Excluding .silverbullet.db* and _plug is indeed a good idea.

1 Like

I have tried to follow this to the letter but keep getting this everytime I try the first commit

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

Updates

(updated in original post)

  • 2025-11-27: Updated to use the Git library instead of plug, added su instructions since docker images may switch user
1 Like