GitHub Tips and Tricks

Published on by

GitHub Tips and Tricks image

I’ve compiled a list of my favorite GitHub tips and tricks that I use in my workflow daily. You might be familiar with some or even all of them, but I find that developers new to GitHub and veterans alike might pick up a new tip or two by sharing!

I’d love to hear from you about your favorite GitHub tips that save you time and improve your code workflow. Here’s my short list of GitHub tips and tricks I’ve loved lately:

Ignore Whitespace in Diffs with the ?w=1 Trick

You can remove whitespace from diffs with the ?w=1 query param. The w=1 query param removes whitespace-only diffs and only shows you lines with code changes. When looking at a large diff with lots of code cleanup and CS fixes this is very helpful to get at the heart of any code changes going along with the whitespace fixes.

I would suggest making separate pull requests for mass whitespace fixes, but sometimes you need to do some cleanup along the way, and removing whitespace diffs is an excellent way to get the point of the pull request quickly.

Commits by Author

You can find the contributions made by an author with the ?author=<github_username> query string param. I find this handy when I want to see my past contributions on a large project or single out a specific developer’s commits on a project. Here are my humble contributions to the Laravel framework, for example.

Linking to Files

This one comes from Derrick Reimer on Twitter. Press ‘y’ to transform the URL into a SHA-based reference:

???? When linking to a file on @github, press 'y' to transform the URL to a SHA-based reference. That way, the link will remain stable even if the underlying file changes in future commits. pic.twitter.com/cAsupEk7tV

— Derrick Reimer (@derrickreimer) May 30, 2018

Sharing the SHA-based reference is evergreen, meaning that the code won’t change in the same way compared to linking to a branch-based file URL like:

https://github.com/laravel/framework/blob/5.6/src/Illuminate/Http/Request.php
 
# VS a hash-based URL
 
https://github.com/laravel/framework/blob/adec8f3b55a7d03305fb8a36b6865206f9a81a8b/src/Illuminate/Http/Request.php

Line Highlighting

Line highlighting is evident from the UI when you click a line number, but you can also link to a range of lines too. For example, the hash #L23-L30 would select the line range of lines 23-30. In tandem with the ‘y’ trick, the SHA-based URL will ensure your line number hash is accurate in the future.

You can also select a range of lines from a file by first clicking a line number from the GitHub UI, holding down “shift” and clicking the ending line:

Cross-Linking Issues

You can cross-link issues and pull requests with the following format in comments, pull request descriptions, etc.:

<organization>/<repo>#<issue_number>

Based on that pattern, here’s an example:

Depends on laravelnews/my-package#123

I love using this tip between my private GitHub repositories and any internal libraries or packages that a pull request depends upon to merge. The other benefit is that GitHub automatically creates a reference in the issue so others can see the relationship.

Organizing Contribution Guidelines

Did you know that you can organize documents like issue templates and contribution guidelines in a docs/ folder or a .github folder? I recently learned about this trick, which is a neat way to organize the files around creating new issues and sharing contribution guidelines.

For example, you can organize the contributing document in the following locations:

contributing.md
docs/contributing.md
.github/contributing.md

Issue templates, pull request templates, and various other project resources work the same way:

.github/ISSUE_TEMPLATE.md
.github/PULL_REQUEST_TEMPLATE.md
.github/SUPPORT.md
.github/CODE_OF_CONDUCT.md

Keyboard Shortcuts

If you’re getting into open-source and using GitHub in general, you can learn about all the keyboard shortcuts available on a given page by hitting “Shift + ?”

Make sure you click “show all” for additional shortcuts, including my favorite shortcut: the ‘t’ key:

Task Lists

You can create task lists in pull requests with markdown like the following:

- [ ] Tests for validation
- [x] Tests for unauthorized access
- [ ] Add indexes to migrations

Which will render as the following in your pull request:

You can check the boxes too once you save the description of a pull request, and you can edit the description to add more todos and manage complete vs. incomplete.

As a bonus, they show up as todo’s on the master list of PRs:

Todos might be something experienced GitHub users are familiar with, but I find that new GitHub users are blown away by this somewhat hidden feature. I use it to communicate that the pull request is still a work-in-progress, and what is still outstanding.

Hub CLI Tool

Hub is a command-line wrapper for git for working with GitHub. You can choose to alias git to hub, or use it as a stand-alone (I prefer the latter):

alias git=hub

With hub you can quickly clone and fork repositories:

hub clone laravel/framework
-> git clone git://github.com/laravel/framework.git
hub fork

In a GitHub project, you can browse the issues with the hub browse command:

hub browse -- issues
 
# or a specific project
hub browse laravel/framework issues
hub browse laravel/framework wiki
hub browse laravel/framework pulls

And my favorite hub command is creating a pull request from the command line, which gives you a git commit-like experience and finally outputs the PR link after creating the pull request:

hub pull-request
 
# check for help info
hub pull-request --help

Check out hub on hub.github.com for install instructions and more examples.

More Tips

Do you have some GitHub tips you love? Reply to Laravel News on Twitter and share your tips with @laravelnews.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article