How to synchronize the contents of local Gitlaba repositories with Github?

For example, to add a commit to Gitlab the same thing appeared in Github.

  • 2
    Nobody bothers you to add yourself two origin'a and commit to the repository, in which you want. And at two at the same time. - KoVadim
  • 2
    Yes, even on cron, pull out of the gitlab and push on the githab. Or on-commit hook. - Nofate

1 answer 1

  1. You can send changes to several repositories with one push command : Send changes to several repositories with one push command
  2. if the server with gitlab is under your control, then you can create a post-commit hook in the repository, which will be called when commits enter this repository. revised and updated example :

    1. on behalf of the user under which gitlab runs , generate a private-public key pair:

       $ sudo -u пользователь ssh-keygen 
    2. add the public part of the key (the id_rsa.pub file in the .ssh in the user's home directory) to the keys of your account on github .
    3. in the directory with the repository on the server with gitlab- th on behalf of the same user, add a new remote with an arbitrary name (for example, togithub ):

       $ sudo -u пользователь git remote add --mirror=push togithub url-репозитория-на-github-е 
    4. in the same directory in the hooks subdirectory, create a file called post-commit the following content:

       #!/bin/sh exec git push togithub -f --mirror 

      and set it executable bits:

       $ sudo chmod +x hooks/post-commit