假设我必须在栅栏后面使用 GIT 服务器,比如在git.mycompany.com
(使用gitea UI)和在git.myclient.com
(使用类似 github 的 UI),两者都使用 VPN、多因素身份验证等高度安全。我想将我的完整存储库交付myProduct
给git.myclient.com/alice/myProduct
Alice是我的联络人。
我可以直接执行此操作而无需绕过计算机上的本地存储库吗?
由于我在远程工作,并且上行mycompany.com
速度比我自己的要快得多...
我目前漫长而缓慢的方法
详细来说,我电脑上的弯路如下:
- 使用(类似 github 的)用户界面,在
git.myclient.com
called 创建一个空的存储库myProduct
。 - 确保我的本地存储库是最新的
git pull
. 检查我当前的远程来源
git config --get remote.origin.url
,例如查看如何确定本地 Git 存储库最初克隆的 URL?就我而言,结果就是
https://git.mycompany.com/b--rian/myProduct.git
- 使用 .将此配置更改为目标存储库
git remote set-url origin git@git.myclient.com:alice/myProduct.git
。 - 使用 为 ssh 生成键值对
ssh-keygen -o
,请参阅https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key - 让 Alice 导航到Settings > GPG 和 SSH 密钥(通常位于 https://git.myclient.com/settings/keys)并让她添加上一步中的新 SSH 密钥。
- 确保 SSH 代理正在我的 Windows 机器上运行,如果没有
eval $(ssh-agent -s)
在 GIT Bash 中启动它,请参阅https://help.github.com/en/github/authenticating-to-github/generating-a-new- ssh-key-and-adding-it-to-the-ssh-agent - 现在,终于,我可以使用
git push --all origin
. 这是我想加快的缓慢步骤。 - 标签必须单独推送,我听说:
git push origin --tags
,请参阅如何使用 Git 将标签推送到远程存储库? - 通过将 设置
remote.origin.url
回第 3 步中的内容来回退所有内容,在我的情况下,它是git remote set-url origin https://git.mycompany.com/b--rian/myProduct.git
.
有没有更简单的方法?