[Tex/LaTex] LaTeX + Git: Bibliography

biblatexbibliographiesbibtexgit

Let's say I have one and only one bibliography file on my computer, in which I write every piece of literature I read and that I import in every paper I write or on what my PhD thesis will be at the end. \nocite{*} allows me to do that without putting uncited literature in my document.
I also use Git for version control of my LaTeX documents.

What I would like to do is to have a new Git repo for my bibliography file and for that file only, which I could ideally pull everytime I need it, update it, use it and push it back to the repo as updated version.

My questions are:

  1. is this a good idea?
  2. once I set up the repo for my bibliography, how do I pull the file in my paper's repo without having two repos in the same folder at the same time? I wouldn't want to refer to any absolute path, as this would make my documents not portable

The bibliography document is supposed to be updated within the paper repo and then pushed to both the paper repo and to the bibliography repo

Best Answer

I use the approach detailed in http://andrius.velykis.lt/2012/06/master-bibtex-file-git-submodules/ for my own work.

So I have one repository "bib" that contains my BibTeX files. For this repository, I also have a private remote at BitBucket for convenience and portability.

In each of my papers and thesis, I use git submodule add <bitbucket-URL> biblio to make a submodule directory with my document. In you document you can then just specify to use the BIB files in that directory.

Typically, I try to only edit my main BIB repository (that's the only one that is loaded within JabRef for me), push those changes to bitbucket and then pull in the changes from within each document repository. However, in some cases I just want to change e.g. how the authors are formatted, don't show URLs in the bibliography for a paper, ... The proper way is to tinker with BST files and the like, but in the heat of the moment it's often a lot faster to just tweak the "biblio" module of a paper.

I think there are a few advantages to this general approach:

  • your bibliography is versioned, so you can easily track what exact version of a BIB file you used,
  • you can transfer changes from your main "bib" repository to each document, or the other way around,
  • you can tweak the bibliography that are specific to one document and not push them back to the main repository,
  • everything can be done using relative paths, so, it is portable across computers, users, OSes, ...

But also some disadvantages:

  • When you add many references, you end up pushing and pulling quite often: push from the main one, pull in the document.
  • Git submodules make your document repository – and how to work with it – more complicated. So you should already feel comfortable with git before you use this a workflow.

Remark about network access While my approach normally relies on bitbucket, I also like to add another remote in the submodule. That extra remote points to the location of my main bibliography repository. This allows me to also push/pull to the main repository when I don't have network access. That extra remote might not migrate well across computers (due to different file paths), but since it's just there "in case of no network", I don't mind it too much.

Remark about submodule In the git world there has been a long-standing discussion whether submodule is a good thing or not. The alternative is to use git subtree, I don't use it, but I suppose the concept of this workflow can be adapted to use subtree instead of submodule.