镜像自托管git存储库到github.com(auth失败)

时间:2013-10-27 17:48:30

标签: git github ssh-agent

我正在尝试将我的个人服务器作为我的主要git远程并自动将其镜像到github。我发现this article主要使用post-receive脚本来执行git push --mirror(基本上)。

我的方法不同之处在于我希望避免创建和保护部署密钥,然后在每个存储库上配置它。

我的收发后脚本可以正常使用以下评论中标记的大多数变体,除非我在上面的博客文章中执行完整的nohup + stdio重定向+后台处理,验证将停止工作。

GITHUB_USERNAME=focusaurus
BARE_PATH=$(pwd -P)
REPO_NAME=$(basename "${BARE_PATH}")
REPO_URL="ssh://git@github.com/${GITHUB_USERNAME}/${REPO_NAME}"
echo "About to mirror to ${REPO_URL}"

#hmm, this works
#git push --mirror "${REPO_URL}"

#this works, too
#nohup git push --mirror "${REPO_URL}"

#and this also works OK
nohup git push --mirror "${REPO_URL}" &

#but this fails with
#Permission denied (publickey).
#fatal: The remote end hung up unexpectedly
#Somehow ssh agent forwarding must get screwed up? Help me, Internet.
#nohup git push --mirror "${REPO_URL}" &>>/tmp/mirror_to_github.log &

#this is the one used in the blog post above but it also fails
# nohup git push --mirror "${REPO_URL}" &>/dev/null & 

我有ssh代理转发,我相信工作版本的工作方式。所以我的问题是为什么最后2个变种因认证错误而失败?

1 个答案:

答案 0 :(得分:1)

也许你可以尝试在ssh上设置详细标志来弄清楚出了什么问题。

您可以使用GIT_SSH环境变量替换git将用于打开ssh连接的命令。从手册页:

   GIT_SSH
       If this environment variable is set then git fetch and git push
       will use this command instead of ssh when they need to connect to a
       remote system. The $GIT_SSH command will be given exactly two
       arguments: the username@host (or just host) from the URL and the
       shell command to execute on that remote system.

       To pass options to the program that you want to list in GIT_SSH you
       will need to wrap the program and options into a shell script, then
       set GIT_SSH to refer to the shell script.

/tmp/verb-ssh中的脚本如下所示:

#!/bin/bash
/usr/bin/ssh -vvv "$@"

然后设置环境变量GIT_SSH=/tmp/verb-ssh应该提供一些有用的调试信息。