Help

How do I push a new project to Overleaf via git?

If you have an existing repository, you can add Overleaf as a remote, just like you would for GitHub or BitBucket. There are a few commands below that you'll need to run to get things started. (The git bridge is still in beta, and we are working on making it possible to skip some of these steps, but until then this process works well.)

To start with, we assume that you have git repo on your computer. (It might also be hosted on github or bitbucket, etc., but you need to have it cloned locally, too).

  1. Create a new project on Overleaf. You can do this from your My Projects dashboard. You might as well use the 'Blank' template, since we're going to overwrite it.

  2. Find the git link for the project from its share menu:
    Share menu with the git link for the example project
    For this example, it's https://git.overleaf.com/4551529zqsdhy.

  3. Add the git link for the project as a remote in your local project.
    $ cd my-paper
    $ git remote add overleaf https://git.overleaf.com/4551529zqsdhy
    
    (Be sure to use your own link, not the example link.)

  4. Pull the latest content from the Overleaf project and merge it into your master branch.

    If using git 2.9 or later, use the commands:

    $ git checkout master
    $ git pull overleaf master --allow-unrelated-histories
    

    In earlier versions of git:

    $ git checkout master
    $ git pull overleaf master
    
    This will create a merge commit that pulls the blank project from Overleaf into your project.

  5. Revert the merge to get rid of the files in the existing Overleaf project.
    $ git revert --mainline 1 HEAD
    

  6. Push your project to Overleaf.
    $ git push overleaf master
    

  7. Visit the project on Overleaf. Your changes will be there. (You may have to open the Project panel to find the new main file.)

Can I do this with Protected projects?

Yes. The only differences are that (1) you'll need to create a new Protected project rather than an unlisted project, and (2) you'll need to sign in to the git bridge using your Overleaf user name and password, in order to access the project.

Important Privacy Considerations

If you have a git repo with both an Overleaf project and a GitHub repo as remotes, the default message for a merge commit will contain the secret link for your Overleaf project. If you are using a public repo on GitHub, please be aware that this will publish the secret link to your project in your commit history on GitHub.

If you would like to keep the secret link secret, you can either make the Overleaf project a Protected Project (available on our Pro plan), so users will require an explicit invite to the project, or use a private repo on GitHub (or BitBucket, etc.).

Credits

Thanks to Tim Korb at Purdue for suggesting this approach.

Thanks to Nicolas Poggi at BarcelonaTech for alerting us to the git 2.9+ issue and its fix.