10 Essential GitHub & Git Tricks to Supercharge Your Workflow
Discover ten practical Git and GitHub shortcuts—including keyboard shortcuts, URL tricks, diff/patch generation, email replies, link sharing, auto‑linking, and powerful Git commands—that can dramatically boost your daily development efficiency and make you a more effective programmer.
Git and GitHub are powerful tools, and even experienced users may miss many useful details.
GitHub shortcuts
Shortcut keys: t and w – Press t on a source‑code browsing page to open fuzzy file‑name search, and press w on a repository home page to filter branches.
Press ? on any GitHub page to display available shortcuts.
Ignore spaces – Append ?w=1 to any diff URL to collapse whitespace.
Range filter commits – Use URLs like github.com/user/repo/compare/{range} where {range} can be sha1…sha2, master…my-branch, or time‑based ranges such as master@{1.day.ago}…master to view commits from a specific period.
.diff and .patch – Append .diff or .patch to a compare, merge‑request, or comment URL to obtain the raw diff or patch text.
Email reply – You can comment directly from a GitHub notification email; GitHub will correctly attach the comment.
Link lines – Clicking a line or selecting multiple lines with SHIFT on a file view updates the URL, making it easy to share specific code snippets.
Watch a user – Mentioning a user in pull requests, issues, or comments subscribes you to all their future notifications.
Auto‑linking – SHA hashes and issue numbers (e.g., #1) are automatically linked; you can also link to other repositories using user/repo@sha1 or user/repo#1.
hub command – hub is the GitHub command‑line tool; for example, hub pull-request creates a pull request directly from the terminal.
Useful Git commands
git log -p FILE – Show the patch for changes to a specific file, e.g., git log -p README.md.
git log -S'PATTERN' – Search commit history for changes containing a specific string, e.g., git log -S'stupid'.
git add -p – Interactively stage or unstage changes.
git rm --cached FILE – Remove a file from the index without deleting it locally, useful for discarding a previously committed ignored file.
git log ..BRANCH – Show commits reachable from BRANCH that are not in the current HEAD, e.g., git log ..master.
git branch --merged & git branch --no-merged – List branches that have been merged into the current branch or those that have not.
git branch --contains SHA – List branches that contain a specific commit SHA, helpful for verifying cherry‑picks.
git status -s – Show a concise status output.
git reflog – Display the local operation history.
git shortlog -sn – List contributors and their commit counts, similar to GitHub’s contributor list.
Git is a well‑designed tool, and mastering these common commands and GitHub shortcuts can make you more efficient and a more skilled programmer. GitHub builds on Git to provide convenient team‑collaboration features, further boosting daily productivity.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
