Md Abdus Samad
  • About
    • News
    • Contact
  • Publications
  • Top Global Scholarships
  • University Information
  • LaTeX
  • Miscellaneous
    • List of Publishers
    • Journal Templates
    • Verifying Journal Indexing
    • Reference, Image Quality, and Detexify
    • Author Services by Major Publishers
    • Document Conversion and Figure Tools
    • Manuscript Anonymization
    • Switching Elsevier LaTeX Templates
    • DOCX to LaTeX Convert
    • LaTeX Reference and Label Management
    • Latex Reference Converter
    • Sequential Section Labels
    • Open Access Journals having Discount Policy
    • Overleaf git sync issues
    • Latexdiff Configuration Guide
    • Open source tools
    • Windows shortcuts & commands
    • Mathpix PDF to Word

On this page

  • Initial Setup (One-Time)
    • 1. Get Your Overleaf Git URL
    • 2. Clone the Project
    • 3. Set Up .gitignore
  • Daily Workflow
    • Before You Start Working
    • While Working
    • After Making Changes
  • Essential Git Commands
    • Viewing Status and History
    • Syncing
    • Undoing Changes
  • Conflict Resolution
    • When Conflicts Occur
    • Abort If Things Go Wrong
  • Best Practices
    • Conflict Prevention
    • Good Commit Messages
    • Working with Branches (Optional)
  • Troubleshooting
    • “Your branch is ahead of ‘origin/master’”
    • “Your branch is behind ‘origin/master’”
    • “Permission denied” or Authentication Failed
    • Accidentally Committed Large Files
    • Want to Start Fresh
  • Quick Reference Card
  • Git Fetch vs Pull
  • Additional Resources

Overleaf Git Sync Guide

Complete Documentation for Safely Syncing Your Overleaf Project with Your PC Using Git

Author

Dr. Md Abdus Samad

Published

May 30, 2025

Complete documentation for safely syncing your Overleaf project with your PC using Git.


Initial Setup (One-Time)

1. Get Your Overleaf Git URL

  1. Open your project in Overleaf
  2. Click Menu (top left)
  3. Click Git
  4. Copy the Git URL (looks like: https://git.overleaf.com/1234567890abcdef)

2. Clone the Project

cd /path/to/where/you/want/project
git clone https://git.overleaf.com/your-project-id
cd your-project-folder

3. Set Up .gitignore

Create a .gitignore file to exclude auxiliary LaTeX files:

Create the file:

# On Linux/Mac/Git Bash:
touch .gitignore

# On Windows Command Prompt:
type nul > .gitignore

# On Windows PowerShell:
New-Item .gitignore -ItemType File

Add this content to .gitignore:

## Core LaTeX auxiliary files
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb

## Bibliography auxiliary files
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml

## Build tool auxiliary files
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.pdfsync

## Build directories
build/
out/

## Editor backup files
*~
*.swp
*.swo

## OS files
.DS_Store
Thumbs.db

Commit the .gitignore:

git add .gitignore
git commit -m "Add .gitignore for LaTeX files"
git push origin master

If auxiliary files are already tracked:

git rm -r --cached .
git add .
git commit -m "Remove auxiliary files from tracking"
git push origin master

Daily Workflow

Before You Start Working

Always pull first to get latest changes:

git pull origin master

While Working

Edit your files normally in your preferred LaTeX editor (VS Code, TeXstudio, etc.)

After Making Changes

1. Check what changed:

git status

2. Stage your changes:

# Stage all changes
git add .

# Or stage specific files
git add filename.tex

3. Commit with a descriptive message:

git commit -m "Add introduction section"

4. Pull with rebase (safer):

git pull --rebase origin master

5. Push to Overleaf:

git push origin master

Essential Git Commands

Viewing Status and History

# See current status
git status

# See commit history
git log

# See compact history
git log --oneline

# See what files changed
git diff

# See changes in a specific file
git diff filename.tex

Syncing

# Download changes without merging (safe)
git fetch origin

# See what is new on remote
git log HEAD..origin/master

# Download and merge changes
git pull origin master

# Download and rebase (cleaner history)
git pull --rebase origin master

# Upload your changes
git push origin master

Undoing Changes

# Discard changes in a file (before commit)
git checkout -- filename.tex

# Unstage a file (keep changes)
git reset filename.tex

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes) - CAREFUL!
git reset --hard HEAD~1

Conflict Resolution

When Conflicts Occur

If you get a conflict during pull or rebase:

1. Git will show which files have conflicts:

CONFLICT (content): Merge conflict in main.tex

2. Open the conflicting file. You will see markers like:

<<<<<<< HEAD
Your local changes
=======
Changes from Overleaf
>>>>>>> origin/master

3. Manually edit the file:

  • Remove the conflict markers (<<<<<<<, =======, >>>>>>>)
  • Keep the version you want (or combine both)
  • Save the file

4. Mark as resolved:

git add main.tex

5. Continue the operation:

# If you were rebasing:
git rebase --continue

# If you were merging:
git commit -m "Resolve merge conflict"

6. Push the resolution:

git push origin master

Abort If Things Go Wrong

# Abort a rebase
git rebase --abort

# Abort a merge
git merge --abort

Best Practices

Conflict Prevention

  1. Always pull before starting work
  2. Commit and push frequently (small commits are better)
  3. Avoid editing the same file in Overleaf and locally simultaneously
  4. Use descriptive commit messages
  5. Use git pull --rebase instead of regular pull for cleaner history

Good Commit Messages

TipGood Examples ✓
git commit -m "Add methodology section"
git commit -m "Fix typo in introduction"
git commit -m "Update bibliography with new sources"
WarningBad Examples ✗
git commit -m "update"
git commit -m "changes"
git commit -m "asdf"

Working with Branches (Optional)

For major changes or experiments:

# Create and switch to new branch
git checkout -b experimental-feature

# Work on your changes...
git add .
git commit -m "Experiment with new structure"

# Switch back to main branch
git checkout master

# Get latest changes
git pull origin master

# Merge your experimental branch
git merge experimental-feature

# Push everything
git push origin master

Troubleshooting

“Your branch is ahead of ‘origin/master’”

Meaning: You have local commits not pushed to Overleaf.

Solution:

git push origin master

“Your branch is behind ‘origin/master’”

Meaning: Overleaf has changes you do not have locally.

Solution:

git pull origin master

“Permission denied” or Authentication Failed

Solution: Check your Overleaf credentials or use a Git credential helper.

Accidentally Committed Large Files

# Remove from last commit
git rm --cached largefile.pdf
git commit --amend -m "Remove large file"
git push origin master --force

Want to Start Fresh

# Discard ALL local changes and match Overleaf exactly
git fetch origin
git reset --hard origin/master
WarningWarning

This deletes all uncommitted local changes!


Quick Reference Card

NoteDaily Workflow
git pull origin master          # Get latest changes
# ... make edits ...
git add .                        # Stage changes
git commit -m "Description"      # Commit changes
git pull --rebase origin master  # Get any new changes
git push origin master           # Upload to Overleaf
NoteCheck Status
git status                       # See what changed
git log --oneline                # See history
git diff                         # See exact changes
NoteUndo
git checkout -- file.tex         # Discard changes in file
git reset --soft HEAD~1          # Undo last commit
CautionEmergency
git rebase --abort               # Cancel rebase
git reset --hard origin/master   # Match Overleaf exactly

Git Fetch vs Pull

git fetch - Downloads changes but does not merge them (safe preview)

git fetch origin
git log HEAD..origin/master  # See what is new
git merge origin/master      # Merge when ready

git pull - Downloads and merges immediately (fetch + merge)

git pull origin master

git pull --rebase - Downloads and applies your changes on top (cleanest)

git pull --rebase origin master

Additional Resources

  • Git Documentation: https://git-scm.com/doc
  • Overleaf Git Guide: https://www.overleaf.com/learn/how-to/Using_Git_and_GitHub
  • Interactive Git Tutorial: https://learngitbranching.js.org/

Last updated: 2025

 

© 2025 Dr. Md Abdus Samad. All rights reserved.