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:
- Create a GitHub repo
- Locally clone your Overleaf repo
- 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)
- Push to the GitHub repo
In more detail:
- Open your Overleaf project, and click on the ‘Share’ button in the header
- Copy the link underneath ‘Clone With Git’ to your clipboard
- In your Terminal, run the following:
git clone [link]
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
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
git remote rename origin overleaf
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.
Copy your new repo’s HTTPS link from the top of the newly displayed page to your clipboard.
Add this as a new remote like so:
git remote add origin [repo link]
If you run
git remote -v, you should now see the new repo link displayed.
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