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

标签 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"

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

最佳答案

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

docker inspect  --format "{{json .HostConfig.PortBindings}}" gogs

以下是设置 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

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

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.

将以下内容添加为您的 Remote :

git remote add origin gogs:yourusername/your-repo.git

请注意,您正在用 gogs ssh 主机条目替换 git@localhost

您现在应该可以推送到您的 gogs 存储库了。

关于git - 将本地 GIT 存储库添加到 Gogs Docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36849356/

相关文章:

git - 特定服务器的 http.sslCAInfo 证书的正确 .gitconfig 语法是什么?

amazon-web-services - 在 aws ECS 集群中显示 docker 容器日志

docker - Nginx反向代理不重定向?

mysql - 尝试使用 docker 连接 MySQL 和 Gogs 容器时出错

git - 如何将 Azure Pipeline 定义 (Json) 保存到另一个 git 存储库

git - "git remote -v"显示 (fetch) 和 (push) 两次,一次用于 'github',一次用于 'origin' 这意味着什么?

docker - 如何彻底阻止容器重启 Kubernetes

laravel - 如何在docker容器内使用php artisan serve?

go - 获取 GO 语言的包

git - "git log"只能显示分支(不是中间提交)吗?