9

我试图让我的个人服务器成为我的主要 git 远程服务器并自动将其镜像到 github。我发现这篇文章主要使用(基本上)可以使用的post-receive脚本。git push --mirror

我的方法不同,因为我想避免必须创建和保护部署密钥,然后在每个存储库上配置它。

我的 post-receive 脚本可以与评论中标记的大多数变体一起正常工作,除非我按照上面的博客文章执行完整的 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 代理转发,我相信这是工作版本的工作方式。所以我的问题是为什么最后两个变体会因身份验证错误而失败?

4

1 回答 1

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应该提供一些有用的调试信息。

于 2013-11-28T14:31:41.967 回答