Web Development

Git Shortcuts That Save Hours: 5 Underrated Commands Most Skip

51 views 4 min read
Git Shortcuts That Save Hours: 5 Underrated Commands Most Skip

Updated October 12, 2026

Most developers waste hours on Git because they rely on basic commands like git commit -m "fix" when faster tools exist. Advanced workflows require precision - below are commands that solve real problems without bloating history or slowing down CI pipelines.

What's new (September 21, 2026): In March 2026, security researchers at Wiz reported CVE-2026-3854, a critical remote code execution flaw (CVSS 8.7) in GitHub's git push pipeline, to GitHub's bug bounty program; GitHub disclosed the flaw publicly on April 28, 2026, according to GitHub's own security team and independent reporting from The Hacker News. Unsanitized git push option values could be injected into internal service headers to run commands as the git user, and GitHub patched github.com about 75 minutes after confirming the root cause, but GitHub Enterprise Server needed a separate fix (3.14.25 or later, depending on your branch). Wiz researchers found the bug through GitHub's public bug bounty program, and GitHub said the flaw could have exposed millions of repositories through cross-tenant access on shared storage nodes, though GitHub's own post states its investigation traced every anomalous occurrence back to the Wiz researchers' own testing and confirmed there was no exploitation. If your team runs GitHub Enterprise Server and relies on force-push workflows like the ones above, confirm you are on a patched version before you push.

Advertisement

What's new (October 12, 2026): Git 2.56, released in late September 2026, added a git add --resolved mode that stages only the paths still marked unmerged in the index and checks them for leftover conflict markers before staging, according to GitHub's own release highlights. For the rebase and cherry-pick workflows below, that is a safer way to stage resolved files than git add -u, which can still sweep in unrelated deletions as the warning further down explains. The same release also sped up git merge-base lookups by stopping the history walk as soon as no new common ancestor can form, cutting one real monorepo's traversal time from 0.68 seconds to 0.01 seconds.

Fix Mistakes Without History Pollution

Edit the last commit without creating a new one using git commit --amend. This is ideal for fixing typos or adding forgotten files before pushing. If you've already pushed, add --force-with-lease to update the remote branch safely.

git add forgotten_file.js
git commit --amend --no-edit
git push origin main --force-with-lease

Cherry-Pick Changes Across Branches

Move specific commits between branches with git cherry-pick. This avoids merging entire feature branches when only a subset of changes is needed. Resolve conflicts interactively by adding -x to preserve the original commit message context.

Github Git Ide
git checkout stable
git cherry-pick abc1234 -x

Rebase to Clean Commit History

Use git rebase -i HEAD~5 to squash messy commits into logical chunks before PRs. This creates a linear history that’s easier to review - but never rebase published commits as it breaks others’ workflows.

✦ Free Newsletter ✦

Never miss a story

Tools, tutorials and AI deep-dives - straight to your inbox, every week.

No spam, unsubscribe any time.
Github Git Ide
git rebase -i HEAD~5
# Mark commits with 'squash' in the editor

Show Only Your Changes in a Repo

Filter Git logs by author to debug ownership issues with git log --author="Your Name". Combine with --since and --until to narrow timeframes. This is invaluable when troubleshooting environment-specific bugs.

git log --author="Jane Doe" --since="2024-01-01" --until="2024-03-01"

Find Deleted Files Instantly

Recover accidentally deleted files with git fsck --lost-found. This lists dangling blobs containing all unreferenced content. Pipe to git show to inspect before recovery - faster than searching through commit history manually.

git fsck --lost-found
git show 0d3a7d...
Stop using git add -u for staged file management. It adds deletions by default, which often includes files you meant to remove from the repo permanently.

Real Tradeoffs

While these commands improve efficiency, they introduce risks. The rebase and cherry-pick workflows become dangerous if used on shared branches. Always communicate before rewriting history in collaborative repos.

Test these commands on feature branches first. Git’s power comes from understanding when automation helps and when it obscures intent - the difference between debugging in minutes and fighting history for hours.

Git Tips That Save Hours: 5 Hidden Tricks Most Skip

Frequently Asked Questions

What does git force-with-lease do
Overrides remote changes safely by verifying the current branch hasn't diverged. Use it instead of --force to avoid overwriting others' work
How to squash Git commits
Use git rebase -i with 'squash' in the editor to merge adjacent commits
Can cherry-pick create conflicts
Yes - apply changes from git diff manually first with --no-commit to resolve them before finalizing the pick

Sources

Share this article:
Advertisement