====== Espejar repo Github -> GitLab ====== La versión Gitlab Enterpise Edition tiene una [[https://docs.gitlab.com/ee/workflow/repository_mirroring.html|funcionalidad ''mirror'']], pero en la versión Community esa funcionalidad no está disponible. Esta es una posible solución que utiliza ''git'' nativo por lo que se adapta a cualquier repo/servicio. ===== Repositorios utilizados ===== * Origen: [[https://github.com/pilasguru/test-sync|https://github.com/pilasguru/test-sync]] * Espejo: [[https://gitlab.com/pilasguru/test-sync|https://gitlab.com/pilasguru/test-sync]] ===== Características del espejo ===== * Se espejan todos los branch del repositorio orígen * Pueden ser repo privados (se require validar acceso) * Se eliminan los pull refs al crear el mirror {{ :docs:shell:git:github-gitlab.png?nolink&700 |}} ===== Proceso manual ===== ==== Configuración ==== $ git clone --mirror git@github.com:pilasguru/test-sync.git Cloning into bare repository 'test-sync.git'... remote: Counting objects: 24, done. remote: Compressing objects: 100% (21/21), done. remote: Total 24 (delta 9), reused 15 (delta 3), pack-reused 0 Receiving objects: 100% (24/24), done. Resolving deltas: 100% (9/9), done. Checking connectivity... done $ cd test-sync.git/ $ git show-ref | cut -d ' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d $ git push --mirror git@gitlab.com:pilasguru/test-sync.git Everything up-to-date Configuración de repositorio local para hacerlo permanente: $ git config -e [core] repositoryformatversion = 0 filemode = true bare = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "github"] url = git@github.com:pilasguru/test-sync.git fetch = +refs/heads/*:refs/heads/* fetch = +refs/tags/*:refs/tags/* mirror = true [remote "mirror"] url = git@gitlab.com:pilasguru/test-sync.git mirror = true skipDefaultUpdate = true ==== Espejar ==== $ git remote update Fetching github $ $ git push mirror Everything up-to-date ===== Proceso automático ===== - Crear una llave ssh //sin passphrase// para el usuario que corre el proceso de espejado - Configurar en **Github** una ''Deploy Key'' con acceso **read-only** (//pull//) del repositorio con la llave publica generada - Configurar en **Gitlab** una ''Deploy Key'' con acceso **write access** (//push//) del repositorio con la llave publica generada $ cd ~/test-sync.git && git remote update && git push mirror Fetching github Everything up-to-date que se puede incluir en el ''cron'' del usuario o del sistema. ===== Referencias ===== * [[https://git-memo.readthedocs.io/en/latest/repository_backup.html#git-mirror|git mirror]] * [[http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html|Git Howto: Mirror a GitHub repo without pull refs]] * [[https://www.quora.com/How-do-I-mirror-a-GitHub-repository-without-pull-requests|How do I mirror a GitHub repository without pull requests?]] * [[https://geekforum.wordpress.com/2015/02/25/move-git-repository-to-new-server/|Duplicating A Git Repository]] * [[http://blog.plataformatec.com.br/2013/05/how-to-properly-mirror-a-git-repository/|How to properly mirror a git repository]]