Gitea sync with my local folder automatically when commit

Hi all,

I have a local folder in my windows server which is a GIT repository.
Then I create a GITea and connect this local folder.
The repositories on both side can be synchronized by git push and git pull commit on server side.
Then I created a hook in local folder, when any file committed in Local folder, it will be automatically sync to GiTea.

However, I don’t know how can I sync the file back to Local folder when any file committed in GitTea.

Please help, Many thanks

I can think of a few options here, in order of difficulty:

  1. Create cron job on Windows server to git pull every 5 minutes. This will synchronize any changes from Gitea after short delay.

  2. Setup push mirror Repository Mirror - Docs. If running Gitea 1.18+, you can choose to automatically push when new commits are added. This is probably unideal solution though since it force pushes and would need an SSH daemon running on Windows server.

  3. Setup custom web server. Configure Gitea repository to have webhook which tells custom web server a new change is published. The custom web server then runs git pull on local repository when it is notified of new change.

1 Like

Thanks a lot,
I am working on your third solution.
I created a php page in another webservice and which can fire “git pull” and work,

but i can’t setup the webhook to make it call my php page.

My php page is very simple.

<?php chdir('C:\HTTP_Sites\DemoGIT'); $output = array(); exec('git pull 2>&1', $output); ?>

How are you setting up webhook? Can you show screenshot of page?

here is my setup

I tried simulating a request from Gitea and I think you are running into these two issues (unless you are overriding DNS internally):

  1. TLS certificate is not valid for that domain. I get
    $ curl -X POST https://[yourdomain]/gitea/git_pull.php
    curl: (60) SSL: no alternative certificate subject name matches target host name '[yourdomain]'
    More details here:
    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
  2. When I bypass TLS check, script cannot be found:
    $ curl -k -X POST https://[yourdomain]/gitea/git_pull.php
    <title>404 Not Found</title>
    <h1>Not Found</h1>
    <p>The requested URL was not found on this server.</p>

If you are overriding DNS internally, try running above commands on your machine and see if they show any errors.

It is my company server, Gitea can connect to that server

Can you try these solutions? Also, are there other webhooks setup on Gitea that are working?

  1. Run “Resynchronize pre-receive, update and post-receive hooks of all repositories” in site administration on Gitea
  2. Make sure the hooks stored inside the git repositories are executable (no GPOs or AppLocker blocking them). I am unfamiliar with Windows but perhaps company IT can check this.
  3. If you are using docker, make sure Docker Server (not the client) >= 20.10.6. Check version by running docker version.

(source: slightly modified FAQ)