Overleaf Git Sync Guide
Complete Documentation for Safely Syncing Your Overleaf Project with Your PC Using Git
Complete documentation for safely syncing your Overleaf project with your PC using Git.
Initial Setup (One-Time)
1. Get Your Overleaf Git URL
- Open your project in Overleaf
- Click Menu (top left)
- Click Git
- 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-folder3. 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 FileAdd 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.dbCommit the .gitignore:
git add .gitignore
git commit -m "Add .gitignore for LaTeX files"
git push origin masterIf auxiliary files are already tracked:
git rm -r --cached .
git add .
git commit -m "Remove auxiliary files from tracking"
git push origin masterDaily Workflow
Before You Start Working
Always pull first to get latest changes:
git pull origin masterWhile Working
Edit your files normally in your preferred LaTeX editor (VS Code, TeXstudio, etc.)
After Making Changes
1. Check what changed:
git status2. Stage your changes:
# Stage all changes
git add .
# Or stage specific files
git add filename.tex3. Commit with a descriptive message:
git commit -m "Add introduction section"4. Pull with rebase (safer):
git pull --rebase origin master5. Push to Overleaf:
git push origin masterEssential 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.texSyncing
# 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 masterUndoing 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~1Conflict 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.tex2. 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.tex5. 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 masterAbort If Things Go Wrong
# Abort a rebase
git rebase --abort
# Abort a merge
git merge --abortBest Practices
Conflict Prevention
- Always pull before starting work
- Commit and push frequently (small commits are better)
- Avoid editing the same file in Overleaf and locally simultaneously
- Use descriptive commit messages
- Use
git pull --rebaseinstead of regular pull for cleaner history
Good Commit Messages
git commit -m "Add methodology section"
git commit -m "Fix typo in introduction"
git commit -m "Update bibliography with new sources"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 masterTroubleshooting
“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 --forceWant to Start Fresh
# Discard ALL local changes and match Overleaf exactly
git fetch origin
git reset --hard origin/masterThis deletes all uncommitted local changes!
Quick Reference Card
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 Overleafgit status # See what changed
git log --oneline # See history
git diff # See exact changesgit checkout -- file.tex # Discard changes in file
git reset --soft HEAD~1 # Undo last commitgit rebase --abort # Cancel rebase
git reset --hard origin/master # Match Overleaf exactlyGit 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 readygit pull - Downloads and merges immediately (fetch + merge)
git pull origin mastergit pull --rebase - Downloads and applies your changes on top (cleanest)
git pull --rebase origin masterAdditional 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