π Pick Commits Like Cherries Need one commit from another branch? Don’t merge everything. Cherry-pick copies specific commits to your current branch. Surgical precision. The Problem # Scenario: Bug fix on wrong branch git branch * feature-login main hotfix # You committed bug fix to feature-login # But it needs to be on hotfix branch […]
Category: Git
Git: Use Interactive Rebase to Clean Up Commit History Before Merge
π§ Rewrite Git History 50 commits saying ‘fix typo’, ‘WIP’, ‘oops’? Messy history before PR? Interactive rebase lets you squash, reword, reorder commits. Clean history like a pro. The Messy History Problem git log –oneline a1b2c3d fix typo d4e5f6g WIP g7h8i9j oops forgot file j1k2l3m fix typo again m4n5o6p actually fix the bug p7q8r9s Add […]
Git: Use git cherry-pick to Copy Specific Commits Between Branches
π Pick Commits Like Cherries Need one commit from feature branch in production? Don’t merge entire branch. Cherry-pick that commit. The Scenario # Feature branch has 10 commits feature-branch: abc123 – Add user login def456 – Fix critical security bug β Need this in production NOW ghi789 – Add dashboard … 7 more commits # […]
Git: Use git stash to Save Work Without Committing
πΎ Save Work, Switch Branch, Come Back Halfway through feature. Emergency bug fix needed. Don’t want to commit messy code. git stash saves work temporarily. The Problem # Working on feature branch git status # modified: feature.js # modified: styles.css # Boss: “Fix production bug NOW!” git checkout main # Error: Your local changes would […]
Git: Use git blame -L to Find Who Wrote Specific Lines
π Who Wrote This Code? Bug in production. Need to know who wrote line 247. git blame tells you author, date, commit. Basic Usage # Entire file git blame filename.js # Specific line range git blame -L 100,150 filename.js # Show line 247 only git blame -L 247,247 filename.js # Output: # abc12345 (John Doe […]
Git: Use Interactive Rebase to Clean Up Commit History
β¨ Rewrite Git History Like a Pro 10 messy commits saying ‘fix’, ‘oops’, ‘wtf’. Interactive rebase turns them into one clean, professional commit. Start Interactive Rebase # Rebase last 5 commits git rebase -i HEAD~5 # Or from specific commit git rebase -i abc1234 # Editor opens with commit list: pick abc1234 Add login feature […]
Git: Use git cherry-pick to Copy Commits Between Branches
Fixed bug in wrong branch. Need same fix in another branch. Don’t want to merge entire branch. # Switch to target branch git checkout main # Cherry-pick specific commit from other branch git cherry-pick abc1234 # Cherry-pick multiple commits git cherry-pick abc1234 def5678 ghi9012 # Cherry-pick range git cherry-pick abc1234..def5678 Conflicts: If conflict occurs, resolve […]
Git: Use git stash -p to Stash Specific Changes
Made 10 changes. Want to stash only 3. git stash takes everything. # Interactive stash (choose what to stash) git stash -p # Git asks for each change: # Stash this hunk? y/n/q/a/d/e y = yes, stash this n = no, keep this q = quit a = stash all remaining d = don’t stash […]
Git: Use git reflog to Recover Deleted Commits
πΎ Git’s Time Machine Accidentally deleted branch? Reset to wrong commit? Reflog saves you. # View all HEAD movements (last 90 days) git reflog # Output shows: # abc1234 HEAD@{0}: reset: moving to HEAD~1 # def5678 HEAD@{1}: commit: Important work β You want this! # Restore that commit git checkout def5678 git checkout -b recovery-branch […]
Git: Use git bisect to Find Bug-Introducing Commit in Minutes
π Binary Search for Bugs Bug appeared somewhere in last 100 commits. Which one? Bisect finds it in 7 tries (logβ 100). git bisect start git bisect bad # Current commit has bug git bisect good abc1234 # This old commit was fine # Git checks out middle commit # You test: does bug exist? […]
Git: Surgical Stashing – Don’t Save Everything!
Sometimes you only want to temporarily hide one file, not your whole workspace. Use git stash push. git stash push -m “temporary fix” path/to/file.js This keeps your other experimental changes active while you fix a bug in a specific file. Total workflow control.
Git: Writing Commits That Your Future Self Won’t Hate
# Bad: fix bug # Good: feat(auth): add password strength validation Follow the Conventional Commits standard. It makes your history searchable and allows for automated changelog generation.
Git: Automating Code Quality with Client-Side Git Hooks
Prevent broken code from even reaching the server. Use a pre-commit hook to run linter and unit tests locally. By placing a script in .git/hooks/pre-commit, you ensure that if tests fail, the commit is blocked. This creates a ‘Quality First’ culture in the development team.
Git: Recovering ‘Lost’ Commits with the Power of Reflog
Did you git reset –hard and lose your work? Don’t panic. Git almost never deletes anything immediately. Reflog tracks every move of the HEAD. git reflog # Find the hash before the mistake git reset –hard [HASH] This is the ‘Undo’ button for your entire Git history. Itβs the difference between a productive day and […]
Git: Ignoring Local Changes to Tracked Files (Config Protection)
Have a local appsettings.json you don’t want to commit, but itβs already tracked? Don’t use .gitignore; use assume-unchanged. git update-index –assume-unchanged config.json Now Git will pretend there are no changes to that file, even if you edit it locally. Perfect for local dev secrets.
Git: Surgical History Edits with Interactive Rebase (fixup)
Interactive rebase is the ‘Photoshop’ of Git history. Use fixup to merge a tiny fix into a previous commit without a trace. git rebase -i HEAD~5 # Change ‘pick’ to ‘fixup’ for your small typo fixes. This results in a clean, linear history where every commit is a meaningful, working feature.
Git: Applying a Specific Fix from One Branch to Another with Cherry-Pick
You fixed a critical bug in the experimental branch, but you aren’t ready to merge the whole branch to production yet. Use Cherry-Pick. git cherry-pick [COMMIT_HASH] This copies only that specific commit’s changes and applies them to your current branch. Surgical and clean.
Git: Finding the Exact Commit That Broke Your App with Bisect
The code was working 2 weeks ago, and now it’s broken. You have 200 commits to check. Don’t do it manually. git bisect start git bisect bad # Current version is broken git bisect good abc123 # This commit was working Git will use binary search to narrow down the culprit in just a few […]
Git: Cleaning Up Your Branch History with Squash and Merge
Nobody needs to see your ‘oops’, ‘fix typo’, and ‘test’ commits in the main history. Use Squash. When merging a feature branch, it combines all 20 of your messy commits into one single, clean commit. This keeps the production history readable and professional.
Git: Saving Hours of Typing with Custom Git Aliases
Stop typing git checkout and git commit. Create professional shortcuts in your .gitconfig. git config –global alias.co checkout git config –global alias.br branch git config –global alias.st status git config –global alias.last ‘log -1 HEAD’ Now, git st does exactly what git status does. Small change, massive daily time savings.
Git: Switching Branches Without Committing Half-Done Work
Your boss wants a quick fix on ‘Main’, but your ‘Feature’ branch is a mess. Use Stash. git stash # Save work to a temporary pile git checkout main # Switch and do the fix git checkout dev # Switch back git stash pop # Bring work back
Git: How to Fix a Typo in Your Last Commit Message
Made a typo in your commit? Don’t delete and start over. Use Amend. git commit –amend -m “Your corrected message” Warning: Only use this for commits that haven’t been pushed to a shared repository yet!
Git Worktrees: Work on Multiple Branches Simultaneously Without Stashing
π The Context Switch Nightmare You’re deep in feature work. Urgent bug reported. You stash, switch branches, fix bug, switch back, pop stash… 20 minutes lost. Your flow? Destroyed. Git Worktrees: Multiple Working Directories, One Repo β The Old Way (Painful) # Working on feature branch $ git status On branch feature/new-dashboard Changes not staged… […]
Git: Use git commit –amend to Fix Last Commit Without New Commit
Forgot to add file or typo in commit message? –amend fixes last commit without creating new one. Fix Commit Message: git commit –amend -m “Corrected message” Add Forgotten Files: git add forgotten_file.js git commit –amend –no-edit # Add to last commit, keep message β οΈ Warning: Never amend commits that are already pushed! Rewrites history = […]
Git: Use git diff –staged to Review Changes Before Commit
Committing without review leads to mistakes. –staged shows exactly what will be committed. See Staged Changes: git diff –staged # Shows changes that are staged (git add-ed) for commit vs git diff: git diff (no flags) shows unstaged changes only. –staged shows what’s going into the commit. Review Workflow: git add . git diff –staged […]
Git: Mastering Worktrees to Handle Multiple Tasks Simultaneously
Stop stashing! git worktree lets you have multiple branches of the same repo checked out in different folders at the same time. You can fix a bug on ‘prod’ without touching your work-in-progress on ‘dev’.
Git: The Ultimate Safety Net – Recovering ‘Deleted’ Work with Reflog
Did you accidentally delete a branch? Or lose a commit during a bad rebase? git reflog is your time machine. It records every single movement of the HEAD, even those not in the history.
Git: Managing Multiple GitHub Accounts with SSH Config
Stop using HTTPS and typing passwords. Use an ~/.ssh/config file to manage work and personal Git accounts seamlessly on one machine.
Git: Cleaning Up Your Commit Mess with ‘Interactive Rebase’
Professionals never push ‘fix typo’ commits. They clean their history first. git rebase -i HEAD~5 This opens an editor where you can squash multiple commits into one clean, professional summary. Your senior dev will love you.
Git: Find the Exact Commit that Broke Your Code with Bisect
When a bug appears and you don’t know when it started, use Git Bisect. It uses binary search to find the faulty commit in seconds.

















