|
| 1 | +--- |
| 2 | +title: "Git Commands That Will Actually Save Your Day" |
| 3 | +linkTitle: "Hidden Git Gems" |
| 4 | +date: 2025-10-02 |
| 5 | +description: "Discover the underrated Git commands that seasoned developers swear by but rarely talk about—powerful tools that solve real problems." |
| 6 | +author: "Jatin Goyal" |
| 7 | +--- |
| 8 | + |
| 9 | +Look, we all know `git commit`, `git push`, and `git pull`. But Git has a treasure trove of commands that can save you hours of frustration—if only you knew they existed. Here are the genuinely useful ones that deserve way more attention. |
| 10 | + |
| 11 | +## `git reflog` — Your Time Machine When Things Go Wrong |
| 12 | + |
| 13 | +Ever executed `git reset --hard` and immediately regretted it? Or accidentally deleted a branch you needed? **This is your safety net.** |
| 14 | + |
| 15 | +```bash |
| 16 | +git reflog |
| 17 | +``` |
| 18 | + |
| 19 | +Reflog shows you *everything* you've done—every commit, reset, checkout, merge. Find the SHA of where you want to be, and: |
| 20 | + |
| 21 | +```bash |
| 22 | +git reset --hard HEAD@{2} |
| 23 | +``` |
| 24 | + |
| 25 | +**Real-world scenario:** You force-pushed to the wrong branch and wiped out work. Reflog lets you recover it. This has saved me more times than I'd like to admit. |
| 26 | + |
| 27 | +## `git add -p` — Stage Like a Pro |
| 28 | + |
| 29 | +Stop staging entire files when you only want some changes. Interactive staging lets you review and stage chunks individually: |
| 30 | + |
| 31 | +```bash |
| 32 | +git add -p |
| 33 | +``` |
| 34 | + |
| 35 | +Git walks you through each change, asking `y/n/s` (yes/no/split). Press `?` for options. |
| 36 | + |
| 37 | +**Why this matters:** You worked on multiple features in one file. This lets you create clean, atomic commits instead of a messy "fixed stuff" commit. |
| 38 | + |
| 39 | +## `git bisect` — Find Bugs Like a Detective |
| 40 | + |
| 41 | +Your code worked last week. Now it doesn't. But there are 50 commits in between. Instead of checking each one manually: |
| 42 | + |
| 43 | +```bash |
| 44 | +git bisect start |
| 45 | +git bisect bad # Current commit is broken |
| 46 | +git bisect good <commit-sha> # This old commit worked |
| 47 | +``` |
| 48 | + |
| 49 | +Git binary-searches through commits. Mark each one as `good` or `bad`, and it finds the exact commit that introduced the bug. |
| 50 | + |
| 51 | +**Time saved:** Instead of checking 50 commits, you check ~6 (log₂ 50). |
| 52 | + |
| 53 | +## `git stash --include-untracked` — Actually Save Everything |
| 54 | + |
| 55 | +Regular `git stash` only saves tracked files. Add new files? They're ignored. This version saves *everything*: |
| 56 | + |
| 57 | +```bash |
| 58 | +git stash -u |
| 59 | +# or |
| 60 | +git stash --include-untracked |
| 61 | +``` |
| 62 | + |
| 63 | +**The situation:** You're mid-feature when production breaks. Stash everything (including those new files), fix prod, then pop your stash and continue. |
| 64 | + |
| 65 | +## `git commit --fixup` — Clean History Without the Hassle |
| 66 | + |
| 67 | +You find a typo in a commit from 5 commits ago. Instead of creating "fix typo" commits: |
| 68 | + |
| 69 | +```bash |
| 70 | +git commit --fixup <commit-sha> |
| 71 | +git rebase -i --autosquash <base-commit> |
| 72 | +``` |
| 73 | + |
| 74 | +Git automatically marks it as a fixup and merges it into the original commit during interactive rebase. |
| 75 | + |
| 76 | +**Result:** Clean history that doesn't show your mistakes (we all make them, but PRs don't need to know). |
| 77 | + |
| 78 | +## `git worktree` — Multiple Branches, Zero Context Switching |
| 79 | + |
| 80 | +Need to check another branch but don't want to stash or commit your current work? |
| 81 | + |
| 82 | +```bash |
| 83 | +git worktree add ../hotfix-branch hotfix |
| 84 | +``` |
| 85 | + |
| 86 | +This creates a *separate working directory* for that branch. Work on both simultaneously. |
| 87 | + |
| 88 | +**Game changer for:** Reviewing PRs while keeping your current work untouched, or testing a feature while developing another. |
| 89 | + |
| 90 | +## `git log --graph --oneline --all` — Visualize Your History |
| 91 | + |
| 92 | +Understanding branch topology is hard. This makes it crystal clear: |
| 93 | + |
| 94 | +```bash |
| 95 | +git log --graph --oneline --all |
| 96 | +``` |
| 97 | + |
| 98 | +Add an alias to make it permanent: |
| 99 | + |
| 100 | +```bash |
| 101 | +git config --global alias.lol "log --graph --oneline --all" |
| 102 | +# Now just use: git lol |
| 103 | +``` |
| 104 | + |
| 105 | +**Pro tip:** Add `--decorate` to see branch and tag names in the visualization. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## The Bottom Line |
| 110 | + |
| 111 | +These aren't party tricks—they're practical tools that solve real problems. The difference between a Git novice and someone comfortable with Git isn't knowing *more* commands; it's knowing *which* commands solve which problems. |
| 112 | + |
| 113 | +Bookmark this. Next time you're stuck, one of these will probably save you. |
| 114 | + |
| 115 | +*What's your underrated Git command? Let me know—I'm always looking for new workflow improvements.* |
0 commit comments