Skip to content

Instantly share code, notes, and snippets.

@jnaecker
Last active June 24, 2023 01:29
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jnaecker/da8c1846bc414594783978b66b6e8c83 to your computer and use it in GitHub Desktop.
Save jnaecker/da8c1846bc414594783978b66b6e8c83 to your computer and use it in GitHub Desktop.
Using Overleaf as your TeX editor but getting your files to Github

git + overleaf + github

Setup

Connect Overleaf and your local repo

  1. Make a new project on Overleaf.
  2. In the share menu, copy the link from "Clone with git"
  3. On your computer:
    • use cd to navigate to where you want to put your project
    • type mkdir and then the name of the project
    • cd into that project
    • do git init
    • do git remote add overleaf with the link you copied
    • so overall this would like something like this
cd ~/Desktop
mkdir overleaf-project
cd overleaf-project
git init
git remote add overleaf https://git.overleaf.com/11205025wxdxfsqpxytc
git pull overleaf master

Connect your local repo and Github

  1. Make a new repo on Github
  2. Copy the git remote link
  3. On your computer:
git remote add github https://github.com/jnaecker/overleaf-project.git
git push github master

Regular Workflow

  1. Make some changes on Overleaf
  2. On your computer (while in the local repo directory), run
git pull overleaf master
git push github master

Any changes you made on overleaf should now be on both your local repo and on Github!

If you want to make changes via your local repo, just push to both remote repos (after staging and committing locally):

git add .
git cm "Adding stuff from local repo"
git push overleaf master
git push github master

You may also want to check out this paper which explains how you get set up git to push to both Overleaf and Github with just one git push command.

@vbuza
Copy link

vbuza commented Jul 16, 2019

Is there a way to add a comment to these steps?

git pull overleaf master
git push github master

Otherwise the commit will just have a generic "Update on Overleaf."

@jnaecker
Copy link
Author

I am not sure, but I don't believe comments can be added on the push or pull steps.

@da5nsy
Copy link

da5nsy commented Jul 24, 2019

This is now (since not sure when?) possible to do within Overleaf (you can push/pull from GH directly).

@jnaecker
Copy link
Author

jnaecker commented Aug 5, 2019

Thanks Danny.

Just curious: How did both of you come across this gist? Very glad if it was helpful for anyone, but I'm shocked multiple people have even seen it.

@da5nsy
Copy link

da5nsy commented Aug 5, 2019

I had messed up the git I was using with Overleaf and was googling around looking for a solution. I think this was one of the top results for Overleaf + Github

@mhdsh1
Copy link

mhdsh1 commented Sep 8, 2020

Hi,
Thanks for the post.
After "git pull overleaf master", I get "Could not resolve host: www.git.overleaf.com" error.
What should I do?

@felixvuo
Copy link

felixvuo commented Mar 16, 2021

Great resource, thank you!

Just one note... your instructions say

In the share menu, copy the link from "Clone with git"

But in Overleaf menu, as I see it today, the section is Sync and the option just says Git rather than Clone with git

Additionally, to Connect your local repo and Github I in fact had to git push github +master to get around complaints that

error: failed to push some refs to 'git@github.com:f__o/l__c.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@pau-arandia
Copy link

Hi there!
Do you happen to know if I can still maintain this overleaf/local repo/github synchronization even if I'm not an Overleaf premium member? I activated my one week free trial just to get the Git link of the project to work.

Before the activation, I got this error:

Pau@DESKTOP-M2GON9N MINGW64 ~/Documents/github-repos
$ git clone -o overleaf https://git.overleaf.com/XXX my-cv
Cloning into 'my-cv'...
fatal: remote error: no git access
This Overleaf project currently has no git access, either because
the project does not exist, or because git access is not enabled
for the project.

where XXX is the identifier that appears in my project link. This is why I went for the free trial.

@jnaecker
Copy link
Author

jnaecker commented May 31, 2023

Hi all -- I continue to be flattered that folks are referring to this quick document I put up as a helpful resource.

Some updates:

First, as @da5nsy noted, you can now push to and pull from GitHub directly in the Overleaf UI. To set this up, go to Menu in the upper right, then under Sync you will see a GitHub option. Click that and follow the directions to connect your Overleaf project to a GitHub repo. You will need to authorize Overleaf to read/write to your GitHub repos. Once things are set up, go to that same location (Menu > Sync > GitHub) to pull in any commits from GitHub or push your recent Overleaf work as a commit. If you want to use Overleaf as your only editor, this should be all you need to leverage GitHub for version control and collaboration.

Second, if you prefer, the original workflow that I outlined above does still seem to work, with a couple caveats:

  • You can get the link for the Overleaf project by going to Menu > Sync > Git, as @felixvuo noted.
  • The default branch name on GitHub is now main instead of master. It seems that Overleaf still expects a branch called master, however. So you may need to rename your main branch with the command git branch -m master. Or you can change the default on your preferences in GitHub.

Finally, note that I was able to do all of these with a basic Overleaf membership. However, the Overleaf documentation does clearly say that both the Git and GitHub integrations are for Premium memberships only. I'm not sure how I was able to get around this; perhaps since I had already set up the integrations a long time ago, I was legacied in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment