Back to Blog
How to Sync Overleaf with GitHub for Free Using GitHub Actions
LaTeXOverleafGitHubTutorialResearch Tools

How to Sync Overleaf with GitHub for Free Using GitHub Actions

March 26, 20265 min read

The Problem

If you're a researcher or a student, you've probably been in this situation: you write your papers on Overleaf because it's convenient, collaborative, and compiles LaTeX in the cloud. But then you realize you have no proper version control, no backup outside Overleaf, and no way to link your paper source to a GitHub repository — unless you pay for Overleaf Premium.

Overleaf's built-in GitHub Synchronization is locked behind a paid subscription. On the free plan, you simply cannot push your project to GitHub through the Overleaf interface.

But there's a workaround — and it's completely free.

The idea is simple: a GitHub Action runs on a schedule (e.g., every few hours), logs into your Overleaf account using a session cookie, downloads your project files, and commits them to a GitHub repository automatically. No Overleaf Premium needed.

We'll use the open-source action overleaf_sync_with_git by subhamX.

What You'll Need

Before we start, make sure you have:

  • A free Overleaf account with at least one project
  • A free GitHub account
  • About 10 minutes of setup time

Step 1 — Create a GitHub Repository

Create a new repository on GitHub for your paper. For example:

  • Name: my-miccai-paper
  • Visibility: Private (you probably don't want your draft public)
  • Initialize with a README: Yes

Step 2 — Get Your Overleaf Project ID

Open your Overleaf project in the browser. Look at the URL — it looks like this:

https://www.overleaf.com/project/64a1b2c3d4e5f6a7b8c9d0e1

The long string after /project/ is your Project ID. Copy it:

64a1b2c3d4e5f6a7b8c9d0e1

This is the trickiest step, but it only takes a minute:

  1. Open Overleaf in your browser and make sure you're logged in
  2. Press F12 to open Developer Tools
  3. Go to the Application tab (Chrome/Edge) or Storage tab (Firefox)
  4. Expand Cookies → click on https://www.overleaf.com
  5. Find the cookie named overleaf_session2
  6. Copy its entire value (it's a long string starting with s:)

Important security notes:

  • After copying the cookie value, delete the cookie from your browser
  • Then log in again to start a fresh session
  • Do NOT log out of Overleaf — logging out revokes the cookie you just copied
  • The copied cookie stays valid for approximately 2 months

Step 4 — Add Secrets to Your GitHub Repository

Go to your GitHub repository → SettingsSecrets and variablesActionsNew repository secret

Add two secrets:

Secret NameValue
OVERLEAF_PROJECT_IDYour project ID from Step 2
OVERLEAF_COOKIEThe overleaf_session2 cookie value from Step 3

Step 5 — Enable Workflow Permissions

Still in your repository settings:

  1. Go to SettingsActionsGeneral
  2. Scroll down to Workflow permissions
  3. Select "Read and write permissions"
  4. Click Save

Step 6 — Create the GitHub Action Workflow

In your repository, create the file .github/workflows/overleaf-sync.yml with this content:

name: Overleaf Sync with Git
 
on:
  schedule:
    # Runs every 6 hours — adjust as needed
    # Cron format: minute hour day month weekday
    - cron: "0 */6 * * *"
  # Allows you to manually trigger the sync
  workflow_dispatch:
 
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Clean up old artifacts
      - name: Delete Old Artifacts
        uses: actions/github-script@v6
        id: artifact
        with:
          script: |
            const res = await github.rest.actions.listArtifactsForRepo({
              owner: context.repo.owner,
              repo: context.repo.repo,
            })
            res.data.artifacts.forEach(({ id }) => {
              github.rest.actions.deleteArtifact({
                owner: context.repo.owner,
                repo: context.repo.repo,
                artifact_id: id,
              })
            })
 
      # Fetch latest files from Overleaf
      - name: Fetch from Overleaf
        uses: subhamx/overleaf_sync_with_git@master
        with:
          OVERLEAF_PROJECT_ID: ${{ secrets.OVERLEAF_PROJECT_ID }}
          OVERLEAF_COOKIE: ${{ secrets.OVERLEAF_COOKIE }}
 
      # Save as artifact (optional backup)
      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: overleaf-project
          path: ./artifacts/
 
      # Commit to the repository
      - uses: actions/checkout@v2
        with:
          path: repo/
 
      - name: Sync files and commit
        run: |
          cd repo/
          mkdir -p overleaf_remote_src
          cp -r ../artifacts/* ./overleaf_remote_src
          git config user.name "Overleaf Sync Bot"
          git config user.email "overleaf-bot@github.com"
          git add .
          if git diff --staged --quiet; then
            echo "No changes to commit"
          else
            git commit -m "Auto-sync from Overleaf $(date +'%Y-%m-%d %H:%M')"
            git push
          fi

Step 7 — Test It

Go to your repository on GitHub → Actions tab → select the "Overleaf Sync with Git" workflow → click "Run workflow".

Wait a minute or two. When it finishes, you should see your Overleaf project files appear in the overleaf_remote_src/ folder of your repository.

From now on, the action will run automatically every 6 hours and commit any changes you've made on Overleaf.

Bonus: Auto-Compile PDF with GitHub Actions

You can extend the workflow to automatically compile your LaTeX to PDF every time it syncs. Add this job after the sync job:

  compile:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Compile LaTeX
        uses: xu-cheng/latex-action@v3
        with:
          root_file: overleaf_remote_src/main.tex
      - name: Upload compiled PDF
        uses: actions/upload-artifact@v4
        with:
          name: compiled-paper
          path: main.pdf

This way, your compiled PDF is always available as a downloadable artifact directly from GitHub Actions — no Overleaf compilation needed.

The Overleaf session cookie expires after roughly 2 months. When it does, the GitHub Action will start failing. To fix it:

  1. Log into Overleaf in your browser
  2. Extract the new overleaf_session2 cookie (same as Step 3)
  3. Update the OVERLEAF_COOKIE secret in your GitHub repository settings

It takes about 30 seconds. Set a calendar reminder every 6-8 weeks.

Summary

With this setup you get:

  • Free Overleaf-to-GitHub sync (no Premium needed)
  • Automatic backups every few hours
  • Full version history on GitHub
  • Optional auto-compilation of your PDF
  • Works with any Overleaf project, including shared ones

The only small inconvenience is refreshing the cookie every couple of months — a small price for a fully automated, free backup pipeline.


If you found this helpful, feel free to share it with your lab mates. Happy writing!