Overleaf with GitHub / GitLab

Overleaf paid accounts can edit Overleaf LaTeX documents offline and Git push / pull with Git direct to Overleaf. Direct Git access does not require special GitHub permissiongs and works with GitLab, GitHub, Bitbucket, etc.

Once the procedure below is done, you’ll be able to:

git push
push local changes (after git commit) to Git provider and Overleaf simultaneously
git push provider
push local changes to only Git provider
git push origin
push local changes to only Overleaf
git pull
pull from Overleaf

For simplicity, this procedure assumes the LaTeX project is existing on Overleaf to start. Starting with a project from the Git provider is more complicated since Overleaf cannot accept force push.

Connect existing Overleaf to Git Hosting provider

Check your current Overleaf LaTeX repo

cd ~/Dissertation
git remote -v

You should see:

origin  https://git.overleaf.com/hash (fetch)
origin  https://git.overleaf.com/hash (push)

Create a new repo Dissertation in the Git hosting provider. Do not create any README, LICENSE, or .gitignore. Then connect Git provider as origin:

git remote add provider ssh://git.invalid/username/Dissertation

git remote set-url origin --add --push https://git.overleaf.com/hash
git remote set-url origin --add --push ssh://git.invalid/username/Dissertation

Verify Overleaf git remote setup

Verify setup by

git remote -v

should be like

provider ssh://git.invalid/username/Dissertation (fetch)
provider ssh://git.invalid/username/Dissertation (push)
origin  https://git.overleaf.com/<hash> (fetch)
origin  ssh://git.invalid/username/Dissertation (push)
origin  https://git.overleaf.com/<hash> (push)

Notes

  • SSH Public Key Authentication is in general recommended for Git (besides Overleaf)
  • One can simultaneously use Overleaf, GitLab, Dropbox, OneDrive, Bitbucket. Just remember to NOT put a LaTeX Git project into a synced Dropbox / OneDrive folder or you’ll get synchronization errors.