brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh browse file.go:42 opens that exact line in your browser

CLI
~/tips/tip-cli-gh-browse-line

gh browse src/app.py:42

Jumps from the terminal to a file, line, issue or settings page of the repository.

You are looking at a line in your editor and want to send a colleague a link to it. Copying the repository URL and clicking through folders takes a minute. gh browse takes a second.

Inside the repository, give it a path, with a line number if you like:

gh browse src/app.py:42
gh browse main.go:312 --blame
gh browse 123

The first opens the file at line 42 on the default branch. --blame opens the blame view for that line. A plain number opens that issue or pull request.

The flags for the common pages save even more clicking: --settings, --releases, --actions, --wiki and --projects. -b picks a branch and -c a commit.

The one I’d remember is -n. It prints the URL instead of opening a browser, so it works over SSH and can go straight to the clipboard:

gh browse src/app.py:42 -n | pbcopy

Line links point at the branch, not a fixed commit, so the line can move when someone edits the file. For a link that has to stay correct, add -c to tie it to the last commit. And the path is relative to the repository root, not to the folder you are in.

Further reading: gh browse (GitHub CLI manual)

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link