LaTeX with GitLab/GitHub and Dropbox backup

The examples show GitLab but of course work equally well with GitHub/Bitbucket/etc. Do not simply drag and drop the LaTeX directory into Dropbox–syncing errors will result.

Git is designed to make simultaneous pushes to multiple remotes. Backup to several sources at once such as LaTeX with Dropbox as backup to GitHub / GitLab, OneDrive or Google Drive with the syncing clients installed.

Given a LaTeX document connected to a GitLab repo, cloned to the computer, backup the LaTeX document folder somewhere else now as a precaution.

git LaTeX repo ↔ Dropbox: git push will go to both simultaneously.

Check current LaTeX repo

cd ~/Dissertation
git remote -v
origin  https://gitlab.com/username/MyDiss (fetch)
origin  https://gitlab.com/username/MyDiss (push)

To create a directory in the Dropbox folder specifically for LaTeX Git repositories, multiple LaTeX projects can be kept in one Dropbox directory. This directory will be referred to as Git.

mkdir ~/Dropbox/Git

Next, set up the Dropbox/Git directory as a second push-only remote. The files will not be visible in this directory because it is a “bare” Git repository, but the history of all files will be recoverable from it in case the LaTeX Git history becomes corrupted.

cd ~/Dropbox/Git
git clone --bare https://gitlab.com/username/MyDiss

cd ~/Dissertation
git remote set-url origin --push --add ~/Dropbox/Git/Dissertation.git
git remote set-url origin --push --add https://gitlab.com/username/MyDiss.git

The --push option indicates that this remote is only for pushing, not for fetching. Normally, fetching (pulling) will be done from GitLab since Dropbox serves as a rolling backup.

Verify the setup with the following command:

git remote -v

The expected output should be:

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

If any issues arise, edit the repository’s Git configuration directly to remove any incorrect pushurl entries:

git -C <repo_dir> config --edit

Since Windows Command Prompt does not recognize ~, ensure that each Terminal used has softlinks created with the same link name. The absolute pathnames differ for WSL, but the softlinks can appear identical.

Windows Subsystem for Linux:

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