LaTeX with Gitlab/Github and Dropbox backup

Related: LaTeX with Gitlab/Github and Dropbox PDF sharing


The examples show Gitlab but of course work equally well with Github/Bitbucket/etc. I use Gitlab because of unlimited free repos.

Do not simply drag and drop your LaTeX directory into Dropbox–you will get syncing errors!

Git is designed to make simultaneous pushes to multiple remote masters. You could backup to several sources at once. Here’s a simple case of using LaTeX with Dropbox as backup to Github/Gitlab. (The same process can be used with OneDrive or Google Drive as well when you have their syncing clients installed.)

Prereq

We assume you already have a LaTeX document connected to a Gitlab repo, cloned to your computer. Backup your LaTeX document folder somewhere else now as a precaution.

Connect git LaTeX repo to Dropbox

When you do git push it will go to both simultaneously.

  1. check your current LaTeX repo
    cd ~/MyDissertation
    git remote -v
    

    You should see:

    origin  https://gitlab.com/username/MyDiss (fetch)
    origin  https://gitlab.com/username/MyDiss (push)
    
  2. Create a directory in your Dropbox folder that is just for your Overleaf Git repos–you can keep multiple Overleaf projects in one Dropbox directory. Let’s call it Git.
    mkdir ~/Dropbox/Git
    
  3. Now setup that Dropbox/Git directory as a second push-only remote. You won’t see your files in there because it’s a “bare” Git repo, but the history of all your files are recoverable from it in case your LaTeX git history gets messed up (as has happened to me with Overleaf!).
    cd ~/Dropbox/Git
    git clone --bare https://gitlab.com/username/MyDiss
    
    cd ~/OverleafDissertation
    git remote set-url origin --push --add ~/Dropbox/Git/MyDiss.git
    git remote set-url origin --push --add https://gitlab.com/username/MyDiss.git
    

    The option --push says this is just for pushing, not for fetching–we’ll normally fetch (pull) from Gitlab since Dropbox is just for rolling backup.

  4. Verify setup by
    git remote -v
    

    and you should see:

    origin  https://gitlab.com/username/MyDiss (fetch)
    origin  https://gitlab.com/username/MyDiss (push)
    origin  /home/computerusername/Dropbox/Git (push)
    

If you have issues, you can edit .git/config directly to get rid of errant pushurl

Note for Windows

On Windows, %userprofile% is equivalent to ~ on Mac/Linux.

Power users of Windows might like to access this setup from WSL or Cygwin. Since Windows Command Prompt doesn’t understand ~, you will have to make sure each Terminal you use (WSL, Cygwin) have softlinks created at the same link_name. Yes, the absolute pathnames are different between WSL and Cygwin, but the softlinks can look the same.

Cygwin

cd ~
ln -s /cygdrive/c/users/joe/Dropbox

Windows Subsystem for Linux

cd ~
ln -s /mnt/c/users/joe/Dropbox

In general I only push/pull from Cygwin or WSL when on a Windows PC because I use SSH on my Git repos with public key authentication.

Leave a Comment