Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maboloshi/9b9a25a93b4f9a0955d1f65391c9572e to your computer and use it in GitHub Desktop.
Save maboloshi/9b9a25a93b4f9a0955d1f65391c9572e to your computer and use it in GitHub Desktop.
[Download a single file from a private GitHub repo] #github #curl

Download a single file from a private GitHub repo.

Relying on basic authentication

#
#依靠基本身份验证从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

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中的参数明文传输

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

作为header中的参数传输

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

Relying on SSH certificate authentication

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

identity_file: 验证私钥文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment