Introduction
When storing KeePass password databases (*.kdbx
files) in Git
repositories, merge conflicts can become a significant hassle. Here's
how to leverage KeePassXC's CLI capabilities to automatically handle
these merges.
Configuration Steps
First, configure Git to use KeePassXC as the merge driver:
git config merge.keepassxc.name "KeePassXC Merge Driver" git config merge.keepassxc.driver "keepassxc-cli merge -s %A %B"
Create or update your .gitattributes
file in the repository root:
*.kdbx merge=keepassxc
This setup tells Git to use KeePassXC's merge functionality whenever it encounters conflicts in .kdbx files.
How It Works
The merge driver integrates with Git's native merge system, automatically handling conflicts in your password databases. When Git detects a conflict in a .kdbx file, it will invoke KeePassXC CLI to perform the merge operation.
Important Considerations
The flag -s
will instruct keepassxc-cli to use the same password for
both databases. You will have to enter the password, though. You can
of course automate this even further by having a file that provides
the password to your database. Straddeling convenience and security is
left as an exercise to the reader. ;)
"keepassxc-cli merge" is not a silver bullet. It can lose data. Make sure to check the output to spot any merges that might have gone haywire.
Naturally this would also be the place to advice to "always backup your database before performing merges" – but hey, your database is already stored in a git repo.
If you liked this post, please consider supporting our Free and Open Source software work – you can sponsor us on Github and Patreon or star our FLOSS repositories.