Download a single file from a private GitHub repo

Relying on basic authentication

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#
#依靠基本身份验证从github企业获取原始内容的单一代码。
#无需创建访问令牌并将其合并到url中。
#
#
#填空:
#
#USER 您用于验证的登录用户名(将在终端上提示您输入密码)
#GHE_DOMAIN github 企业自定义域
#REPO_OWNER 拥有存储库的用户/组织
#REPO_NAME 资料库的名称
#REF git ref,例如分支或提交(大多数情况下,您可能希望使用“ master”)
#FILE 要获取的文件的路径,包括文件扩展名。 也用作本地创建文件的名称
#OAUTH-TOKEN 二步验证码

curl -u "${USER}" -O https://${GHE_DOMAIN}/raw/${REPO_OWNER}/${REPO_NAME}/${REF}/${FILE}

参考:

Accessing GitHub using two-factor authentication

1
curl -u "${USER}" -H "X-GitHub-OTP: ${OTPCODE}" -O https://${GHE_DOMAIN}/raw/${REPO_OWNER}/${REPO_NAME}/${REF}/${FILE}

Relying on OAuth2 token authentication

You’ll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use

作为url中的参数明文传输

1
curl -O https://${OAUTH-TOKEN}@${GHE_DOMAIN}/raw/${REPO_OWNER}/${REPO_NAME}/${REF}/${FILE}

作为header中的参数传输

1
curl -H "Authorization: token ${OAUTH-TOKEN}" -O https://${GHE_DOMAIN}/raw/${REPO_OWNER}/${REPO_NAME}/${REF}/${FILE}

Relying on SSH certificate authentication

1
scp [-i identity_file] ${USER}@${GHE_DOMAIN}:${REPO_OWNER}/${REPO_NAME}.git/${REF}/${FILE}  /path/to/local/file

identity_file: 验证私钥文件