Gitea post-recieve hook to push repo

Hi everyone, happy gitea user here :slight_smile:

I want to push a repo from my gitea server to a diffrent remote git server (gitlab).

So i created a post-recieve hook for the repository under repository -> settings -> git hooks -> post-recieve

 #!/bin/bash
while read oldrev newrev ref
do
     if [[ $ref =~ .*/master$ ]];
     then
         echo "master ref. push blog to gitlab.. " 
         git push gitlab master
     else
         echo "not on master branch.. "
     fi
done

Everytime i push code to my gitea server now, i get the following response:

remote: master ref. push blog to gitlab.. 
remote: fatal: 'gitlab' does not appear to be a git repository
remote: fatal: Could not read from remote repository.
remote: 
remote: Please make sure you have the correct access rights
remote: and the repository exists.

I have created a ssh-keypair for the git user (the user running gitea) and placed it in ~/.ssh
Also i’ve pasted the public key of the git user into my gitlab account under settings -> SSH Keys.
Using gitea version 0549762 with docker.

Is there something iam missing? Is my post-recieve hook wrong?

Any help appreciated! :slight_smile:

Thanks in advance and have a nice day.

Push mirroring was made a CE feature in GitLab two months ago so it should be possible. According to the error gitlab is not a valid remote. Have you reached out to GitLab for support? If they supported the kind of mirroring Gitea does you wouldn’t be having this problem.

Cant use the feature of gitlab because my gitea server is not reachable from the outside. Its just an local docker container.

Ive also addded gitlab as a remote with:
git remote add git@gitlab.com:gitlab_user/repo.git
but i still get the error.

I havent tried to contact the gitlab support, wanted to make sure i dont have any dumb problems on my side with gitea.

Thanks for your reply balibebas :slight_smile:

1 Like

Are you able to push up from a terminal inside your container manually?

Not exactly sure where i find the repo to try a manual push.
But i just created a test-repo on gitlab, pulled it inside the container and pushed it after a minor change again to gitlab.

I had to configure git user credentials
git config --global user.name “John Doe”
git config --global user.email johndoe@example.com

maybe i have to add this to the repo i want to push with the post-recieve hook?

I’m not 100% sure as I haven’t tried this myself, but perhaps this will help:

According to Gitea docs looks like git repos are stored in custom/git. Since your using Docker check your Gitea volume for the precise location. That should help get you out of the black box it sounds like your in so you can debug properly.

This helped me. Never saw that there are “deploy keys”, i think i have to use thoose instead of just general ssh keys i added before.

I followed the instructions, now i get the following error:

remote: master ref. push blog to gitlab.. 
remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote: 
remote: Please make sure you have the correct access rights
remote: and the repository exists.

feels like iam getting closer… thanks alot balibebas! :slight_smile:

iam going to test more around and test my google skills again … this project is getting way more complicated that i acutally wanted :confused:

1 Like

Glad to hear you’re making measured progress. If Google doesn’t deliver why not try DuckDuckGo after a small break and I bet you’ll get it. You’re teaching me things I wanted to know but wrote off before I started. Cheers.