что такое mirror git
Руководство для начинающих: Git Mirrors
Прежде чем мы углубимся в подробности, давайте посмотрим, зачем вам нужно зеркалирование Git.
Зачем нужно зеркалирование Git
Вы можете начать проект в частном порядке, а позже решить открыть его исходный код на GitHub.
Как вы можете это сделать что без потери истории коммитов?
Давайте попробуем другой пример, где вы хотите обновить свой сервер репозитория или попробовать переместить репозиторий Git между двумя серверами без потери его истории, веток и т. д.
Что вы будете делать?
Git mirroring может помочь вам ответить на эти вопросы.
Что такое Git mirroring
Git mirroring — это когда зеркало копирует refs все, что указывает на совершить и ветки удаленного отслеживания. Предполагается, что это будет функционально идентичная копия, взаимозаменяемая с оригиналом.
Синтаксис
Проще говоря, он будет делать следующее:
Как использовать Git mirror
Шаг 1
Первый шаг прост. Вам необходимо отразить репозиторий Git на свой локальный компьютер. Вы можете использовать эту команду:
Итак, приведенная выше команда Git создаст каталог с именем вашего репозитория.
Шаг 2
Шаг 3
Пришло время установить URL-адрес нового сервера в вашем репозитории Git. Вы можете запустить команду из папки репозитория git:
Шаг 4
Пора нажать на репозиторий:
Запустив указанную выше команду Git, вы продвигаете весь репозиторий Git со всей его историей фиксации и ветвями.
Заключение
С помощью параметра Git Mirror вы можете сохранить ваша ценная история коммитов с другими важными ссылками и ветками удаленного отслеживания.
Прошли те времена, когда разработчики вручную копировали код с одного сервера на другой.
When people talk about mirroring a git repository, usually we have a simple answer in mind:
Just git clone the repo and you’re set!!
However, what we want with mirroring is to replicate the state of an origin repository (or upstream repository). By state, we mean all the branches (including master ) and all the tags as well.
You’ll need to do this when migrating your upstream repository to a new “home”, like when switching services like GitHub.
As with most tools, there’s a lot of ways to accomplish that, but I’ll be focusing on two of them. The difference lays on whether you already have a working copy of that repository or not.
Mirroring a git repository without a local copy
If you haven’t cloned the repository before, you can mirror it to a new home by
This will get all the branches and tags that are available in the upstream repository and will replicate those into the new location.
Warning
Mirroring a git repository if you already have a local working copy
By working copy, we mean a “normal” repository, in which you have the files that are being tracked into git and where you perform commands like git add and so on.
Cleaning old references to remote branches
Finally, mirroring the repository to a new location
Now we’re ready to send those updated references back to the origin repository:
Ok, what just happened here?!
The + sign indicates that we want to overwrite any reference there may already exist.
—prune means we want to delete any reference that may exist there if we don’t have such reference in our refs/remotes/origin/* (and tags) references.
Conclusion
Git is certainly not an easy tool to learn. Although when you do, it turns into a very powerful and flexible tool.
What about you? Have any tips on git you want to share?
Repository mirroring
You can mirror a repository to and from external sources. You can select which repository serves as the source, and modify which parts of the repository are copied. Branches, tags, and commits can be mirrored.
Create a repository mirror
If you select SSH public key as your authentication method, GitLab generates a public key for your GitLab repository. You must provide this key to the non-GitLab server. To learn more, read Get your SSH public key.
Update a mirror
Force an update
Mirror only protected branches
Moved to GitLab Premium in 13.9.
You can choose to mirror only the protected branches in the mirroring project, either from or to your remote repository. For pull mirroring, non-protected branches in the mirroring project are not mirrored and can diverge.
To use this option, select Only mirror protected branches when you create a repository mirror.
Authentication methods for mirrors
SSH authentication
For SSH authentication, you provide your credentials as a password or public key. The server that the other repository resides on provides its credentials as a host key. You must verify the fingerprint of this host key manually.
Get your SSH public key
If you must change the key at any time, you can remove and re-add the mirror to generate a new key. Update the other repository with the new key to keep the mirror running.
Verify a host key
Related topics
Troubleshooting
Should an error occur during a push, GitLab displays an Error highlight for that repository. Details on the error can then be seen by hovering over the highlight text.
Received RST_STREAM with error code 2 with GitHub
If you receive this message while mirroring to a GitHub repository:
Deadline Exceeded
Connection blocked because server only allows public key authentication
The connection between GitLab and the remote repository is blocked. Even if a TCP Check is successful, you must check any networking components in the route from GitLab to the remote server for blockage.
This error can occur when a firewall performs a Deep SSH Inspection on outgoing packets.
Could not read username: terminal prompts disabled
If you receive this error after creating a new project using GitLab CI/CD for external repositories:
When connecting to the repository for mirroring, Bitbucket requires the repository owner in the string.
Pull mirror is missing LFS files
Как создать локальное зеркало удаленного репозитория GIT?
1@R00T /C/GIT
$ cd mono.git
Вроде пушиться в локальный репозитории по https отлично:
Welcome to Git (version 1.9.5-preview20141217)
Run ‘git help git’ to display the help index.
Run ‘git help ‘ to display help for specific commands.
1@R00T /C/GITHUB
$ git clone https://1@git.local/r/mono.git
Cloning into ‘mono’.
Password for ‘https://1@git.local:
remote: Counting objects: 6, done
remote: Finding sources: 100% (6/6)
remote: Getting sizes: 100% (4/4)
remote: Compressing objects: 100% (71/71)
remote: Total 6 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (6/6), done.
Checking connectivity. done.
1@R00T /C/GITHUB
$ cd mono
1@R00T /C/GITHUB/mono (master)
$ touch test
1@R00T /C/GITHUB/mono (master)
$ git add test
1@R00T /C/GITHUB/mono (master)
$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from ‘matching’ to ‘simple’. To squelch this message
and maintain the current behavior after the default changes, use:
To squelch this message and adopt the new behavior now, use:
When push.default is set to ‘matching’, git will push local branches
to the remote branches that already exist with the same name.
In Git 2.0, Git will default to the more conservative ‘simple’
behavior, which only pushes the current branch to the corresponding
remote branch that ‘git pull’ uses to update the current branch.
Что такое mirror git
Scripts for setting up and synchronizing two-way mirroring between Git repositories. There are instructions for one-way mirroring below as well.
Sets up a remote Git repository mirror.
Warning: mirroring may destroy revisions in either repository.
There’s locking to assure that two script runs don’t step on each other’s toes.
Simple one-way mirroring setup:
Add system user, generate key, share the key with source repository owner:
Test that cloning works:
Create mirror repository:
Create synchronization script, test:
Add synchronization script to /etc/crontab (with e.g. 30-minute interval):
GitLab repositories that need two-way synchronization with an origin repository need a different setup.
As GitLab uses hooks to track changes in repositories, a separate satellite repository is needed for two-way mirroring that fetches from the origin repository and pushes to GitLab and vice-versa.
In the following, GitLab Omnibus installation is assumed.
Setup satellite repository for mirroring
Login as the GitLab git user in the GitLab server, generate SSH key:
Create a dedicated GitLab mirroring account in GitLab web interface, upload the SSH public key into the account profile.
Create the mirror project in GitLab web interface, give Master access to the mirroring account.
Copy the SSH public key to origin repository SSH authorized keys:
Assure SSH server accepts connections to localhost in GitLab server.
Setup the mirroring tools workspace for git user and configure git-mirror :
Run the setup script:
The setup script does the following:
Assure passwordless access works, no password propmts should appear during setup.
Add the line that was printed in the end of setup scrip run to crontab :
Test and examine logs.
It seems that deleting and creating branches from the GitLab web UI does not trigger the post-receive hook in GitLab, so deleted branches will be resurrected during next update from origin. This problem has been filed as bug #1156 in the GitLab issue tracker.
About
Scripts for setting up and synchronizing two-way mirroring between two Git repositories