Version Control SQLite files in Git


To put sqlite3 files under version control, I do the following.

My sqlite3 files have the extension ‘.db’.

  1. I added these lines to ~/.gitconfig:
[filter "sqlite3"]
	clean = "f() { tmpfile=$(mktemp); cat - > $tmpfile; sqlite3 $tmpfile .dump; rm $tmpfile; }; f"
	smudge = "f() { tmpfile=$(mktemp); sqlite3 $tmpfile; cat $tmpfile; rm $tmpfile; }; f"
	required = true
  1. In each git repositories where there is (are) db file(s), I add a file called .gitattribute at the root of the directory whith this content:
*.db filter=sqlite3

Thanks to this blog!