Syncing Your GitHub Repo with Overleaf - jamiefogel/Networks GitHub Wiki

Thought for a few seconds

Syncing Your GitHub Repo with Overleaf

This guide shows how to link your GitHub repo Networks with your Overleaf project WhatIsALaborMarket using Git remotes. Once set up, you can seamlessly edit on GitHub, locally, or in Overleaf—and keep everything in sync.


1. Big-Picture Overview

  • GitHub origin

    • URL: [email protected]:you/Networks.git
    • Your canonical source: all .tex files, figures, tables, etc.
  • Overleaf overleaf remote

    • URL: something like https://git.overleaf.com/abcdef123456
    • Mirrors the same files into your Overleaf project WhatIsALaborMarket.
  • Local clone

    • You work here. Pull/push to both remotes as needed.

2. Prerequisites

  1. You’ve created a blank Overleaf project named WhatIsALaborMarket.
  2. You can log in to both GitHub and Overleaf.
  3. You have Git installed locally.

3. Wiring Up the Remotes

  1. Clone (or cd into) your existing GitHub repo

    git clone [email protected]:you/Networks.git
    cd Networks
    ```q
    
    
  2. Add Overleaf as a second remote

    • In Overleaf: open 🔧 Menu → Git and copy the “Git clone URL” (e.g. https://git.overleaf.com/abcdef123456)
    • In your terminal:
      git remote add overleaf https://git.overleaf.com/abcdef123456
      
  3. Verify your remotes

    git remote -v
    # origin   [email protected]:you/Networks.git (fetch)
    # origin   [email protected]:you/Networks.git (push)
    # overleaf https://git.overleaf.com/abcdef123456 (fetch)
    # overleaf https://git.overleaf.com/abcdef123456 (push)
    

4. One-Way Sync: GitHub → Overleaf

Whenever you push new commits to GitHub and want to mirror them in Overleaf:

# 1. Make edits locally
git add .
git commit -m "Add new figure and update section 2"

# 2. Push to GitHub
git push origin main

# 3. Push the same branch to Overleaf
git push overleaf main

Overleaf will immediately update WhatIsALaborMarket and recompile the PDF.


5. Two-Way Editing: Overleaf ↔ GitHub

A. Edit in Overleaf → Push to GitHub

  1. Make edits in the Overleaf web editor.
  2. Fetch & merge your Overleaf commits locally:
    git fetch overleaf
    git merge overleaf/main
    
  3. Push merged changes back to GitHub:
    git push origin main
    

B. Edit Locally or on GitHub → View in Overleaf

  1. Edit locally or merge a PR on GitHub.
  2. Push to Overleaf:
    git push overleaf main
    
  3. Overleaf auto-recompiles with the new content.

6. Handling Merge Conflicts

  • If you and someone else edit the same lines in both places, you’ll see a conflict when merging:
    git merge overleaf/main
    
  • Resolve conflicts in your local editor, then:
    git add .
    git commit
    git push origin main
    git push overleaf main
    

7. (Optional) Automate with GitHub Actions

To automatically mirror every push to main on GitHub into Overleaf, add:

# .github/workflows/overleaf-sync.yml
on:
  push:
    branches: [ main ]

jobs:
  push-to-overleaf:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Push to Overleaf
        run: |
          git remote add overleaf https://git.overleaf.com/abcdef123456
          git push overleaf main --force

Now a git push origin main also updates Overleaf.


8. Summary

  1. Local work in your Networks clone.
  2. Two remotes: origin (GitHub) and overleaf (Overleaf).
  3. Push to either or both to sync changes.
  4. Pull/Merge from Overleaf when you edit in the browser.

You get GitHub’s version control and CI plus Overleaf’s collaborative LaTeX environment—without manual uploads or file-count limits.