Overleaf with Github

Alternative: Switch from Overleaf to Github + Dropbox PDF sharing

Backup your Overleaf LaTeX document folder somewhere else now as a precaution. Of course, you can substitute Bitbucket or Gitlab etc. for Github. Once the procedure below is done, you’ll be able to

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

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

1a. Connect existing Overleaf to Github

  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 github. Do not create any README, LICENSE, or .gitignore. Then connect Github as origin:

     git remote rename origin overleaf
     git remote add origin https://github.com/<githubusername>/MyDissertation
     git remote set-url origin --add --push https://git.overleaf.com/<hash>
     git remote set-url origin --add --push https://github.com/<githubusername>/MyDissertation

1b. Connect existing Github to Overleaf

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

  1. if you haven’t already, clone your Github LaTeX repo to your PC.

     git clone https://github.com/<githubusername>/MyDissertation
  2. create a new blank Overleaf project. Go into Share and copy the https://git.overleaf.com/. 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://github.com/<githubusername>/MyDissertation
  4. merge the blank Overleaf project with

     git pull overleaf master

    you need --allow-unrelated-histories if using Git 2.9 or newer. 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/Github/Bitbucket git setup

Verify setup by

    git remote -v

and you should see:

    origin  https://github.com/<githubusername>/MyDissertation (fetch)
    origin  https://git.overleaf.com/<hash> (push)
    origin  https://github.com/<githubusername>/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.

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

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

Other possible Overleaf + Github configurations

  • SSH Public Key Authentication will also work (and is in general strongly recommended for any Git use)
  • You can simultaneously use Overleaf, Github, 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