Sync git repository with an Overleaf project
- Create a project in overleaf:
- Create a blank project, no complex stuff is required
- Note: you must login with an email and password and not through a Google account. It is needed to push to the overleaf afterward since it doesn't support SSH keys by default.
- Get git link:
- Once you've created a project, go to the menu, in the section called
Sync
you can findGit
. Go there.- If you have created a new account, this feature will be paid only. For this purpose you have to use our shared credentials, see on this page "Overleaf credentials" here, use them to log in and get GitLab link.
- This will open a pop-up window with
git clone https://git.overleaf.com/<your overleaf project link>
. Copy thehttps...
link.
- Sync your repo:
- Recommendation: cache the credentials so you don't have to type them all the time:
git config credential.helper "cache --timeout 3600"
- Add remote: open your repo, and run command:
git remote add overleaf <https link from step 2 >
- Pull the overleaf repository while synchronizing the histories:
git pull overleaf master --allow-unrelated-histories
- Resolve merge conflicts:
git mergetool
- Push to overleaf:
git push overleaf master
- (optional) Pulling from overleaf:
git pull overleaf master
Two-branch setup (recommended)
Overleaf automatically pushes its changes. As you don't want anyone to mess with your master branch, create a two-branch setup in which you are free to push/pull/merge as you wish.
- Create an overleaf branch:
git checkout -b overleaf
- Push your changes at
overleaf
branch to Overleaf:git push overleaf overleaf:master
- Pull to this branch from Overleaf:
git pull overleaf master:overleaf
- Or pull using
merge
as
git fetch
git checkout overleaf
git merge overleaf/master