obsidian git
- https://publish.obsidian.md/git-doc/Getting+Started
- https://publish.obsidian.md/git-doc/Authentication
- Fine-grained personal access token
Start a GitHub repository and a obsidian vault
- I already had an Obsidian vault synced to a GitHub repository. In this procedure I am just laying out what I did to start using the Obsidian Git plugin.
Utilize a .gitignore
file
- This helps avoid populating commits with unnecessary changes
Verify your using https
for the remote repository URL.
If the above code block is not similar use the example below to modify it.
Create a fine-grained PAT
- Fine-grain PAT in GitHub Settings / Developer Settings
- Under
Permissions
chooseRepository permissions
and set onlyContents
toAccess level
→Read and write
. This gives give permission to push to the repository.
Install libsecret
- Since
https
is being used we need to way to automate entering in the username and password every time we try to push to the repository.
- If the above example does not work try this one below.
Verify git configuration
- git config —global —list
$ git config --global --list
user.name=Michael Miller
user.email=miketm89@gmail.com
credential.helper=/usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
- Once you have libsecret setup and perform a
git push
you will be prompted to input the username and password (use the PAT from previous step). After you do this once libsecret will remember and start passing them automatically.
$ git push
Username for 'https://github.com': digitalhabitat
Password for 'https://digitalhabitat@github.com':
Extras
I was curious to learn more about libsecret and how it manages the stored credentials. It turns out that you can use secret-tool
to do exactly that. First install the tool with the example below.
sudo apt install libsecret-tools -y
However, the usage text is not extremely helpful.
$ secret-tool
usage: secret-tool store --label='label' attribute value ...
secret-tool lookup attribute value ...
secret-tool clear attribute value ...
secret-tool search [--all] [--unlock] attribute value ...
secret-tool lock --collection='collection'
In this example, am able to pull the credentials for my specified GitHub username. It might not be obvious but on closer inspection you will notice that there are no attributes stored that could differentiate the same user, on the same hosting provider, but accessing a different repository. I am not entirely certain but I imagine that the PAT for specific repositories will have issues utilizing libsecret because libsecret has no way of knowing which repository specific PAT to use or may fail to authenticate altogether because its using the wrong repository specific PAT.
$ secret-tool search --all user digitalhabitat
[/8]
label = Git: https://github.com/
secret = <password from PAT>
created = 2023-12-27 20:35:22
modified = 2023-12-27 23:39:20
schema = org.gnome.keyring.NetworkPassword
attribute.protocol = https
attribute.user = digitalhabitat
attribute.server = github.com