This guide outlines the steps to integrate your Overleaf project with a GitHub repository. This integration allows you to collaborate on your LaTeX documents using Overleaf while also version-controlling your project on GitHub. This project more or less tries to bypass the (paid) Github integration as offered by Overleaf.
Note
I recently discovered that Git integration is part of a premium service, which means if you have a paid plan you can direclty integrate your project with Github making this automation useless. However, in case of a collaborative project where the owner have premium access to Overleaf in that case only Git is available and not GitHub. In such cases this might come handy. This is also useful if you have Git and GitHub integration but you don't use GitHub, you can use this to sync your project to other Git based repository hosting services.
- Git installed on your local machine.
- An Overleaf project that you want to connect to a GitHub repository.
- A GitHub repository where you want to store the version-controlled code.
Clone your Overleaf project to your local machine using the following commands:
git clone <Overleaf_project_URL> <Overleaf_project_directory>
cd <Overleaf_project_directory>
Create a private repository on Github with main
branch initialised.
Add your GitHub repository as a remote to your local Overleaf project:
git remote add <github_remote_name> <GitHub_repository_URL>
git fetch <github_remote_name>
Create and switch to a local branch that will track the main branch of your GitHub repository:
git checkout -b <local_branch_name> <github_remote_name>/main
That's all for the manual git setup.
git clone [email protected]:sahiljhawar/git-overleaf-sync.git
and install colorama
for colored terminal output:
pip install colorama
Warning
Only works with python3
python3 main.py --path <Overleaf_project_directory [fullpath]> --local <local_branch_name> --refresh <refresh time in seconds>
Use <Overleaf_project_directory>
and <local_branch_name>
as used during the intial setup
Code should be self explanatory. However, here's a short overview:
After the initial setup, the script calculates the MD5 hash at current state and then pulls from the Overleaf, and then calculates the hash again, if the previous hash and new hash are different, a merge takes place from Overleaf branch to Github branch and changes are pushed to Github. There are no commits made to the Overleaf and no pulls made from the Github. Your local system merely works as a (toned down) proxy and syncs the two repositories. There are obvious optimisations which can be made such as use of
gitpython
, error handling, logging, etc.