Migrating an Overleaf project to GitHub

I’ve been a big proponent of Overleaf for some time now, having written both committee reports and assignments in it to great success in my grad school career thus far. Recently, I expanded my horizons a bit and made my first conference poster in LaTeX – something I admittedly found a bit head-spinning at first, but which eventually clicked just like everything else about LaTeX has in the past.

After returning from the conference (and recovering from a good bit of jet lag) I decided I wanted to preserve the project within a GitHub repo: code, plots, and all. Why? Partially in the spirit of working open, and making my TeX and R code available to anyone who cares to use it – and partially just to immortalize that mini-project within its own repo.

Turns out Overleaf makes this even easier than I’d expected it to be. My naive assumption was that I’d have to download the files from the Overleaf project and manually put together a GitHub repo, but a few shell commands and tinkering on GitHub is all it takes!

The key here is that each Overleaf project is itself a git repo. Thus, in order to ‘export’ it to GitHub, the key is to:

  1. Create a GitHub repo
  2. Locally clone your Overleaf repo
  3. In your local clone, add the GitHub repo as a new remote (and, optionally, rename your Overleaf remote so that it can also be pushed to)
  4. Push to the GitHub repo

In more detail:

  1. Open your Overleaf project, and click on the ‘Share’ button in the header
  2. Copy the link underneath ‘Clone With Git’ to your clipboard
  3. In your Terminal, run the following:
git clone [link]
  1. The Overleaf project will be cloned into a new folder within your current directory. The name seems to be a mishmash of characters, unfortunately - it may be worth renaming it to something more informative using mv.

  2. Have a look at your remotes with git remote -v. You’ll notice the two links are both to git.overleaf.com - these remotes link to the Overleaf project. We can rename these from origin to overleaf like so:

git remote rename origin overleaf
  1. Open up GitHub and create a new repo. Make sure you do not initialize your repo with either a README.md file or a .gitignore.

  2. Copy your new repo’s HTTPS link from the top of the newly displayed page to your clipboard.

  3. Add this as a new remote like so:

git remote add origin [repo link]
  1. If you run git remote -v, you should now see the new repo link displayed.

  2. Push the contents of the project to GitHub:

git push -u origin master

You can now sync your local copy with these two remotes separately. In my case, I added the R script I used to make my plots, but only pushed that to the GitHub repo:

git add plots.R
git commit -m 'add plot code'
git push -u origin master