Overleaf with Github

Alternative: Switch from Overleaf to Github + Dropbox PDF sharing

Note, I use Gitlab for LaTeX because of unlimited free repos. You can of course swap in Github, Bitbucket, &c.

Backup your Overleaf LaTeX document folder somewhere else now as a precaution.

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

git push
push local changes (after git commit) to Gitlab and Overleaf simultaneously
git push origin master
push local changes to only Gitlab
git push overleaf master
push local changes to only Overleaf
git pull
pull from Gitlab only
git pull overleaf master
pull from Overleaf (normally just use Gitlab)

Pick ONE of the following connections (1a) or (1b).

1a. Connect existing Overleaf to Gitlab

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

    You should see:

    origin  https://git.overleaf.com/hash (fetch)
    origin  https://git.overleaf.com/hash (push)
  2. Create a new repo MyDissertation in Gitlab. Do not create any README, LICENSE, or .gitignore. Then connect Gitlab as origin:
    git remote rename origin overleaf
    git remote add origin https://gitlab.com/username/MyDissertation
    git remote set-url origin --add --push https://git.overleaf.com/hash
    git remote set-url origin --add --push https://gitlab.com/username/MyDissertation

1b. Connect existing git repo to Overleaf

If you did the procedure above, you don’t need this procedure.

  1. if you haven’t already, clone your Gitlab LaTeX repo to your PC.
    git clone https://gitlab.com/username/MyDissertation
  2. create a new blank Overleaf project. Go into Share and copy the https://git.overleaf.com/hash. Rename in Overleaf main.tex to junk.tex
  3. connect Overleaf as a second Git remote by
    git remote add overleaf https://git.overleaf.com/hash
    git remote set-url origin --add --push https://git.overleaf.com/hash
    git remote set-url origin --add --push https://gitlab.com/username/MyDissertation
  4. merge the blank Overleaf project with
    git pull overleaf master

    you need --allow-unrelated-histories if using Git ≥ 2.9. if your Overleaf project is brand new

    git revert --mainline 1 HEAD
  5. finally update Overleaf, then visit to see your document there.
    git push overleaf master

2. Verify Overleaf git remote setup

Verify setup by

git remote -v

and you should see:

origin  https://gitlab.com/username/MyDissertation (fetch)
origin  https://git.overleaf.com/<hash> (push)
origin  https://gitlab.com/username/MyDissertation (push)
overleaf https://git.overleaf.com/<hash> (fetch)
overleaf https://git.overleaf.com/<hash> (push)

SECURITY NOTE for Github with Overleaf

If you choose to also use Github public repos with public Overleaf project, note that merge commits default log message reveals your “secret” Overleaf URL, enabling anyone to edit your public Overleaf project.

Use Gitlab with unlimited free private repos instead of Github perhaps.

Mitigation: either of these will work to solve the security risk with public Overleaf project secret URL. I choose to use a private Gitlab repo.

  • make your Overleaf project private, so that a login/password is required to edit.
  • make your Gitlab repo private–the number of pushes are still tracked to show you’re active.

Other possible Overleaf + Git configurations

  • SSH Public Key Authentication will also work (and is in general strongly recommended for any Git use)
  • You can simultaneously use Overleaf, Gitlab, Dropbox, OneDrive, Bitbucket, etc. as many remotes as you want. Just remember to NOT put your active LaTeX files into a synced Dropbox/OneDrive folder or you’ll get synchronization errors. Let Git do its work properly.

Leave a Comment