将本地 GIT 存储库添加到 Gogs Docker 容器

Ole*_*Ole 5 git docker gogs

我已经使用 Docker 安装了 Gogs。随后我创建了一个这样的本地存储库(实际上它repository有多个分支等,但我只是让这个例子保持简单):

mkdir repository
cd repository
git init
touch README.md
git add README.md
git commmit -m "How do I get this into Gogs"
Run Code Online (Sandbox Code Playgroud)

我现在如何将其迁移/推送到 Gogs?

Col*_*ney 4

要将变更集推送到 gogs,您需要在 gogs 上创建一个存储库,然后添加一个使用容器启动时公开的端口的远程。如果您不确定,请运行以下命令并记下 HostPort 条目。假设容器名为 gogs:

docker inspect  --format "{{json .HostConfig.PortBindings}}" gogs
Run Code Online (Sandbox Code Playgroud)

以下是设置 ssh 远程源的步骤。使用 3000/tcp 的 HostPort 条目访问的 gogs Web UI 添加您的公钥。如果您按照 gogs docker 说明进行操作,则可能是:http://localhost:10080如果 gogs 未在本地运行,请将 localhost 替换为 gogs 主机名。

添加以下主机条目以~/.ssh/config更轻松地指定备用 ssh 端口:

Host gogs
    # if gogs is not running locally, add the remote hostname here
    Hostname localhost
    User git
    # the following should match what is listed for HostPort 22/tcp
    port 10022
Run Code Online (Sandbox Code Playgroud)

使用 测试 ssh 主机条目ssh gogs。如果它有效,你应该看到:

PTY allocation request failed on channel 0
Hi there, You've successfully authenticated, but Gogs does not provide shell access.
If this is unexpected, please log in with password and setup Gogs under another user.
Connection to localhost closed.
Run Code Online (Sandbox Code Playgroud)

添加以下内容作为您的遥控器:

git remote add origin gogs:yourusername/your-repo.git
Run Code Online (Sandbox Code Playgroud)

请注意,您将替换git@localhostgogsssh 主机条目。

您现在应该能够推送到您的 gogs 存储库。