跳到正文
Skillpedia
部署与云(DevOps)40k · #7221

gh-attach

它能做什么

这个工具可以帮你把文件(比如图片或文档)上传到 GitHub,并在讨论中使用,例如 bug 报告或代码审查请求。它还可以下载别人上传到 GitHub 的文件。

适用场景

  • ✓需要在 bug 报告中添加截图时。
  • ✓想在代码修改请求中附上文件时。
  • ✓想下载别人在 GitHub 上分享的文件时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/gh-attach/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/gh-attach/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“把这张截图附加到我的 bug 报告里。”

每周 5 个新技能,1 分钟读完。

工作原理

工具在后台使用 GitHub 的一个专用命令上传你的文件,然后生成一个链接,GitHub 会自动识别并直接显示。下载时,它会使用同样的链接,并结合你的 GitHub 登录信息来获取文件。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

gh-attach

gh attach uploads a file to GitHub's internal user-attachments endpoint (no public API exists) and prints the URL, which GitHub auto-renders (image/video/file) wherever it's pasted. The URL inherits the repo's visibility, so private-repo uploads stay private.

Prerequisites

gh extension list | grep -q 'gh attach' || gh extension install sudosubin/gh-attach

Uploads use a GitHub browser session cookie, not the gh token. By default, gh must be authenticated so gh-attach can select the matching browser account. If the wrong account is selected, add --browser <name> --profile <name>. For headless use, set GH_ATTACH_SESSION_TOKEN to the bare user_session cookie value. Treat it as a full account credential.

Steps

1. Upload: Use an absolute quoted path. -R is optional inside a repository. For GHES, use -R host/owner/repo. The command prints the URL on one line. GitHub auto-renders it (image/video/file), so use it as-is:

URL=$(gh attach "$FILE" -R <owner>/<repo>)

2. Embed (always --body-file -, e.g. gh pr comment/edit, gh issue comment/edit):

printf '## Screenshots\n\n%s\n' "$URL" | gh pr comment <pr> -R <owner>/<repo> --body-file -

3. Download: Specify the destination explicitly. Private attachments use the active gh token, with browser cookies as an authorization fallback:

gh attach download "$URL" -O "$FILE"

Notes

  • Private repo: URL renders only for authorized viewers. An anonymous fetch is expected to return 404 or 403.
  • Sizing: embed <img width="800" src="$URL"> instead of the bare URL.
  • GitHub Cloud and GHES decide which file extensions and content types they accept.
常见问题

如果文件来自私有仓库,会怎样?

如果文件上传到了私有项目中,那么只有有权限查看该项目的人才能通过链接看到文件。

我可以调整讨论中图片的大小吗?

可以。你可以用简单的 HTML 代码指定图片尺寸,例如 `<img width="800" src="FILE_URL">`。

可以上传哪些类型的文件?

具体支持哪些文件类型和内容类型由 GitHub 决定。一般来说,图片、PDF、视频和压缩包都是支持的。

详情

作者的原始描述

Uploads a local file (screenshot, image, PDF, zip, video) to GitHub user-attachments, downloads GitHub user-attachments, and embeds local files in a PR, issue, or comment. Use when asked to "attach a screenshot to the PR", "add an image to the issue", "embed before/after screenshots", "attach this file", or "download this GitHub attachment". Powered by `gh-attach`.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7221
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能