【问题标题】:Backing up full remote git repository with history to another remote server将带有历史记录的完整远程 git 存储库备份到另一个远程服务器
【发布时间】:2020-09-22 06:19:16
【问题描述】:

假设我必须在栅栏后面使用 GIT 服务器,比如git.mycompany.com(带有gitea UI)和git.myclient.com(带有类似 github 的 UI),两者都使用 VPN、多因素身份验证等高度安全. 我想将我的 完整 存储库 myProduct 交付给 git.myclient.com/alice/myProduct,因为 Alice 是我的联系人。

我可以直接执行此操作,而无需绕过我计算机上的本地存储库吗?

由于我在远程工作,而且mycompany.com的上行速度比我自己快很多...

我目前漫长而缓慢的方法

详细来说,我电脑上的弯路如下:

  1. 使用(类似 github 的)用户界面,在 git.myclient.com 创建一个名为 myProduct 的空存储库。
  2. 确保我的本地存储库是最新的git pull
  3. 使用git config --get remote.origin.url 检查我当前的远程来源,参见例如an answer to How can I determine the URL that a local Git repository was originally cloned from?

    就我而言,结果就是https://git.mycompany.com/b--rian/myProduct.git

  4. 将此配置更改为使用git remote set-url origin git@git.myclient.com:alice/myProduct.git 的目标存储库。
  5. 使用ssh-keygen -o为ssh生成一个键值对,见https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key
  6. 让 Alice 导航到 设置 > GPG 和 SSH 密钥(通常在 https://git.myclient.com/settings/keys) 并要求她添加上一步中我的 新 SSH 密钥
  7. 确保 SSH 代理正在我的 windows 机器上运行,如果没有在 GIT Bash 中使用 eval $(ssh-agent -s) 启动它,请参阅 https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
  8. 现在,我终于可以使用git push --all origin 将大部分内容推送到客户端了。 这是我想加快速度的缓慢步骤。
  9. 标签要单独推送,听说:git push origin --tags,见How do you push a tag to a remote repository using Git?
  10. 通过将 remote.origin.url 设置为第 3 步中的内容来回退所有内容,在我的情况下,它是 git remote set-url origin https://git.mycompany.com/b--rian/myProduct.git

有没有更简单的方法?

【问题讨论】:

    标签: windows git github clone gitea


    【解决方案1】:

    也许您可以在 git.myclient.com 上使用 Git 镜像。

    这取决于客户 VCS (Git)。大多数实现都有镜像选项。

    例如,如果客户端使用的是 Gitlab: https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html

    【讨论】:

    • 我猜你的意思是git push --mirror git@git.myclient.com:alice/myProduct.git 还是什么?在mycompany.com 方面,我有gitea,但我不知道如何在那里做,请查看我的编辑。
    • Git 镜像必须在您的客户端 GIT 软件上设置。所以他们的 GIT 会时不时地(可以配置,例如 2 分钟)将所有更改拉到他们的仓库中。
    • 好吧,我在问,因为我读过github.com/go-gitea/gitea/issues/9766,但不知何故,我在myclient.commycompany.com 之间没有设法在直接路径上进行镜像,因为我在身份验证方面遇到了麻烦之间。
    • 是的,这是让我们说您 GIT 上的技术用户(只读)的先决条件,它将在客户端 GIT 上用于身份验证和镜像。
    • 是的,在这种情况下,我会使用第二个遥控器。但无论如何,建议也是为您创建一个脚本。如果此脚本可以在 Jenkins 或您在项目开发期间用于服务的某些 VPS 上运行,那就更好了。
    【解决方案2】:

    我认为添加第二个遥控器会更简单......然后推入那个遥控器:

    git remote add second url-to-new-repo
    git push second master develop # push master and develop to second
    

    等等。

    【讨论】:

    • 我完全忽略了非常有效的观点。另一方面,我想,我正在寻找一个 gitea 的选项,我可以用于镜像。
    猜你喜欢
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 2020-05-30
    • 2012-12-06
    • 1970-01-01
    相关资源
    最近更新 更多