【问题标题】:Deployment from private github repository从私有 github 存储库部署
【发布时间】:2012-11-14 11:30:05
【问题描述】:

我是 git 和 github 的新手(我之前使用过 Subversion)。我找不到如何将主分支仅从我的私有存储库导出到我的生产服务器的解决方案。

我需要准备一个自动化解决方案(通过 fabric 调用)。我发现 git 有存档命令,但这不适用于 github(我设置了 SSH 密钥):

someuser@ews1:~/sandbox$ git archive --format=tar --remote=git@github.com:someuser/somerepository.git master
Invalid command: 'git-upload-archive 'someuser/somerepository.git''
  You appear to be using ssh to clone a git:// URL.
  Make sure your core.gitProxy config option and the
  GIT_PROXY_COMMAND environment variable are NOT set.
fatal: The remote end hung up unexpectedly

所以我需要另一种方法来做到这一点。我不想在导出中使用来自 git 的任何元文件。当我克隆时,我会将所有这些文件放在 .git 目录中(我不想要的),这会下载比我真正需要的更多的数据。

有没有办法通过 ssh 做到这一点?还是我只能通过 HTTPS 下载 zip?

【问题讨论】:

    标签: deployment github


    【解决方案1】:

    我不确定我是否完全理解您的问题。

    我使用此命令将当前主版本拉到我的服务器:

    curl -sL --user "user:pass" https://github.com/<organisation>/<repository>/archive/master.zip > master.zip
    

    这有帮助吗?

    【讨论】:

    • 是的,类似的。我认为我也可以通过 SSH 获取它,但可能不行。我发现这些步骤 (help.github.com/articles/…) 使用令牌而不是密码,但这不起作用。
    • 前段时间我也尝试过该教程,但它对我也不起作用...... :) 如果答案对你有帮助,欢迎 V 它;)
    • 有没有人找到使用 ssh 的 git 归档解决方案?我也面临同样的问题。
    【解决方案2】:

    正如我在SO answer on downloading GitHub archives from a private repo 中解释的那样,在创建GitHub access token 之后,您可以使用wgetcurl 来获取您的repo 所需的&lt;version&gt;(例如masterHEAD,提交SHA -1, ...)。

    wget 的解决方案:

    wget --output-document=<version>.tar.gz \
        https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN>
    

    curl 的解决方案:

    curl -L https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN> \
        > <version>.tar.gz
    

    【讨论】: