Why
GitHub rejects pushes if a single file is over 100 MB (GH001: Large files detected). Warning comes already from 50 MB.
Git LFS is not a good choice for GitHub Pages, because Pages does not serve LFS files (link gives only the LFS pointer file).
Solution: attach the file to a GitHub release. Release assets are not part of the git history, and one file can be up to 2 GB.
Remove big file from the last commit
If the file is only in the last (not yet pushed) commit:
git rm --cached path/to/big-file.pdf
git commit --amend --no-edit
git push
--cached removes the file only from git, the file stays on the disk. Add the path also to .gitignore if needed.
If the file is in older commits, use git filter-repo or BFG to remove it from the history (needs force push).
GitHub CLI (gh)
Install and login (only once):
winget install GitHub.cli
gh auth login
Run commands in the repository directory or add --repo <owner>/<repo> (for example --repo octocat/my-repo).
Create new release with file
gh release create manuals "C:\path\to\user-manual.pdf" --title "Manuals" --notes "User manuals"
manualsis the tag name and it is used in the download url- many files at once:
gh release create manuals file1.pdf file2.pdf --notes-file notes.mdreads release notes from a file--draftcreates a draft which is not public until published--target masterselects the branch/commit for the new tag (default is the default branch)
Update existing release
| Command | Description |
|---|---|
gh release upload <tag> file.pdf |
add new file to existing release |
gh release upload <tag> file.pdf --clobber |
add file and overwrite the old file with same name |
gh release delete-asset <tag> file.pdf |
remove file from release |
gh release edit <tag> --title "New title" --notes "New notes" |
change title and notes |
gh release edit <tag> --draft=false |
publish draft release |
gh release list |
list releases |
gh release view <tag> |
show release and its files |
gh release download <tag> --pattern "*.pdf" |
download files from release |
gh release delete <tag> --cleanup-tag |
delete release and also its tag |
Example, replace the PDF with a new version:
gh release upload manuals "C:\path\to\user-manual.pdf" --clobber
HOX! The download url does not change when file is overwritten with the same name.
GitHub web UI
New release
- Open the repository in GitHub and click
Releases–>Draft a new release - Choose a tag (write a new one, for example
manuals, and selectCreate new tag) - Write title and description
- Drag the file to
Attach binaries by dropping them here - Click
Publish release
Update release
Releases–> select the release –> click the pencil icon (Edit)- Remove the old file with the
xicon and/or drag the new file - Click
Update release
Link to the file
Url format:
https://github.com/<owner>/<repo>/releases/download/<tag>/<file name>
For example:
https://github.com/octocat/my-repo/releases/download/manuals/user-manual.pdf
Use this link in the page instead of the local file path:
<a href="https://github.com/octocat/my-repo/releases/download/manuals/user-manual.pdf">Manual</a>
Latest release (works only for the newest release):
https://github.com/<owner>/<repo>/releases/latest/download/<file name>
Tips
- One release can hold many files, so you do not need a new release for every file. Use
gh release upload. - Spaces in file names are changed to dots by GitHub, so use file names without spaces.
- Browser downloads the file, it does not necessarily open it inside the page.