GitHub Tips and Tricks

GitHub is a developer platform that allows developers to create, store, and manage their code. If you’re new to GitHub, or if you’ve been using it for years and have yet to look into shortcuts, I figured I’d share a few handy GitHub tips and tricks.

GitHub Keyboard Shortcuts

If you navigate to a repo page, and press ? (or Shift + /) GitHub will show you a modal with a list of quick keyboard shortcuts, as well as a link that displays all the available shortcuts.

GitHub shortcuts

One of my favorite ones to use is typing / or s when you’ve navigated to a repo page, since it allows you to pull up the file search.

Autodelete GitHub Branches

You can automatically delete GitHub branches after pull requests have been merged into your repo. This is great for managing your repo’s branches so that they don’t get out of control. To set up the automatic deletion of branches, navigate to the settings for a specific repo. On the “General” settings page, under the “Pull Requests” section, select “Automatically delete head branches.”

Link to Specific Lines of Code in a GitHub Repo

If you click the number beside a line of code, it will highlight the line and display a few menu options. If you click “Copy permalink” you’ll have access to a link that will link to the code snippet even if the file is later updated or deleted on the main branch. If you hold down shift while selecting lines of code, you can select several lines to highlight and link to.

Close GitHub Issues Automatically with Keywords in your Commit Messages

You can automatically close issues fixed by commits by using a keyword followed by the issue number in the commit message, i.e. git commit -m "fixes #30"

Here’s a list of all the keywords you can use to automatically close issues:

close #30
closed #30
closes #30
fix #30
fixed #30
fixes #30
resolve #30
resolved #30
resolves #30

Handy GitHub URLs

GitHub uses a few URL patterns that are handy for getting access to diffs of code or even user avatars:

  • Avatars: https://github.com/<username>.png
  • Diff of a commit: https://github.com/<repo-owner>/<repo>/commit/<sha>.diff
  • Patch of a commit: https://github.com/<repo-owner>/<repo>/commit/<sha>.patch
  • Diff of a pull request: https://github.com/<repo-owner>/<repo>/pull/<id>.diff
  • Patch of a pull request: https://github.com/<repo-owner>/<repo>/pull/<id>.patch
  • Latest release: https://github.com/<repo-owner>/<repo>/releases/latest

Format your GitHub README.md with Markdown

When visiting a GitHub repo, GitHub will serve the repo’s README.md. You can make these documents pretty elaborate by including a project overview, info on how to run the project locally, deployment info, etc. I like to use a project’s repo as the single source of truth for that project and keep it updated as processes change and as adjustments are made to various environments. You can find some basic markdown formatting info via GitHub’s documentation. One helpful tip for markdown formatting that I enjoy using, is that the <details></details> tags allow you to hide/show content via a simple accordion.

Host Web Pages and Simple Applications with GitHub Pages

You can host a GitHub Pages site for free via your GitHub account. This is great for simple websites and applications. You can even customize the domain URL, but the out-of-the-box URL is <your-github-username>.github.io/<repo-name>. You can find out more about using GitHub pages here.

Leave a Reply