Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: Git

Git

Git: Surgical Fixes with Cherry-Pick – Move One Commit, Not the Branch

- 21.02.26 - ErcanOPAK comment on Git: Surgical Fixes with Cherry-Pick – Move One Commit, Not the Branch

Fixed a critical bug on ‘dev’ but not ready to merge the whole branch to ‘prod’? Use git cherry-pick [hash].

Read More
Git

Git: Keep History Clean with Squash Rebase

- 21.02.26 - ErcanOPAK comment on Git: Keep History Clean with Squash Rebase

Don’t let ‘fixed typo’ or ‘test’ commits ruin your main branch. Merge them into one clean commit before pushing. git rebase -i HEAD~3 # Pick first, squash others

Read More
Git

Git: Use ‘Stash Pop’ to Move Work Between Branches

- 21.02.26 - ErcanOPAK comment on Git: Use ‘Stash Pop’ to Move Work Between Branches

Started working on the wrong branch? Stash your changes, switch branch, and pop them back. git stash git checkout correct-branch git stash pop

Read More
Git

Git: Use git clean to Remove Untracked Files Safely

- 21.02.26 - ErcanOPAK comment on Git: Use git clean to Remove Untracked Files Safely

Manual deletion of generated files is tedious. git clean removes all untracked files at once. ⚠️ Test First (Dry Run): git clean -n # Shows what WOULD be deleted without actually deleting Remove Untracked Files: git clean -f # Force remove files Remove Untracked Files AND Directories: git clean -fd # -d = directories Remove […]

Read More
Git

Git: Use git revert Instead of git reset for Shared Branches

- 21.02.26 - ErcanOPAK comment on Git: Use git revert Instead of git reset for Shared Branches

git reset rewrites history – dangerous on shared branches. git revert creates new commit that undoes changes safely. ❌ Wrong – git reset on Shared Branch: git reset –hard HEAD~1 # Removes commit from history git push –force # DANGEROUS – rewrites history for everyone! # Team members’ branches now out of sync ✅ Right […]

Read More
Git

Git: Use .gitattributes to Handle Line Endings Across OS

- 17.02.26 - ErcanOPAK comment on Git: Use .gitattributes to Handle Line Endings Across OS

Team uses Windows and Mac? Mixed line endings (CRLF/LF) cause constant unnecessary diffs. Fix with .gitattributes. Create .gitattributes in repo root: # Normalize all text files to LF in repo * text=auto # Force LF for these file types *.js text eol=lf *.ts text eol=lf *.css text eol=lf *.html text eol=lf *.json text eol=lf # […]

Read More
Git

Git: Use git notes to Add Comments to Commits Without Changing History

- 17.02.26 - ErcanOPAK comment on Git: Use git notes to Add Comments to Commits Without Changing History

Want to add context to old commits without rewriting history? Git notes attach metadata to any commit. Add Note to Commit: # Add note to last commit git notes add -m “Reviewed by John. Deployed to staging 2024-03-15” # Add note to specific commit git notes add -m “This fixed the prod outage on Black […]

Read More
Git

Git: Use git sparse-checkout to Clone Only Specific Folders

- 16.02.26 - ErcanOPAK comment on Git: Use git sparse-checkout to Clone Only Specific Folders

Cloning huge repo when you only need one folder wastes time and disk. Sparse checkout downloads only what you need. Clone with Sparse Checkout: # Clone repository (no files yet) git clone –no-checkout https://github.com/user/repo.git cd repo # Enable sparse checkout git sparse-checkout init –cone # Specify folders you want git sparse-checkout set frontend/src backend/api # […]

Read More
Git

Git: Use git switch and git restore Instead of Confusing git checkout

- 16.02.26 - ErcanOPAK comment on Git: Use git switch and git restore Instead of Confusing git checkout

git checkout does too many things (switch branches, restore files, create branches). Git 2.23+ splits it into clear commands. Old Confusing Way: # Switch branch git checkout main # Create and switch to new branch git checkout -b feature # Restore file git checkout — file.txt # All same command! Confusing! New Clear Commands: # […]

Read More
Git

Git: Use git log –graph to Visualize Branch History

- 15.02.26 - ErcanOPAK comment on Git: Use git log –graph to Visualize Branch History

Understanding branch history in text is hard. –graph flag shows visual tree. Pretty Graph: git log –graph –oneline –all # Output: # * abc1234 (HEAD -> main) Merge feature # |\ # | * def5678 (feature) Add feature # | * ghi9012 Feature progress # * | jkl3456 Fix bug # |/ # * mno7890 […]

Read More
Git

Git: Use git reflog to Recover Lost Commits After Reset

- 15.02.26 - ErcanOPAK comment on Git: Use git reflog to Recover Lost Commits After Reset

Accidentally did git reset –hard and lost commits? Reflog keeps history of all HEAD movements. View Reflog: git reflog # Output: # abc1234 HEAD@{0}: reset: moving to HEAD~3 # def5678 HEAD@{1}: commit: Important feature ← Lost commit! # ghi9012 HEAD@{2}: commit: Bug fix Recover Lost Commit: # Option 1: Checkout specific commit git checkout def5678 […]

Read More
Git

Git: Use git worktree to Work on Multiple Branches Simultaneously

- 15.02.26 - ErcanOPAK comment on Git: Use git worktree to Work on Multiple Branches Simultaneously

Switching branches loses unsaved work. Worktree creates separate folder for each branch. Create Worktree: # Create worktree for feature branch git worktree add ../myproject-feature feature-branch # Now you have: # ~/myproject/ (main branch) # ~/myproject-feature/ (feature branch) Work in Both: Open both folders in separate VS Code windows – work on both branches at once! […]

Read More
Git

Git: Use git cherry-pick to Copy Specific Commits Between Branches

- 15.02.26 - ErcanOPAK comment on Git: Use git cherry-pick to Copy Specific Commits Between Branches

Need one commit from another branch but not all changes? Cherry-pick copies specific commits. Pick Single Commit: # Find commit hash you want git log feature-branch –oneline # abc1234 Fix critical bug # Switch to target branch git checkout main # Cherry-pick that commit git cherry-pick abc1234 # Commit is now in main branch! Pick […]

Read More
Git

Git: Use git blame -L to See Who Changed Specific Lines

- 14.02.26 - ErcanOPAK comment on Git: Use git blame -L to See Who Changed Specific Lines

Whole file blame is overwhelming. See only who changed specific lines you care about. Blame Specific Line Range: # See who changed lines 50-60 git blame -L 50,60 file.js # See who changed from line 100 to end git blame -L 100,+1000 file.js Ignore Whitespace Changes: # Ignore commits that only changed indentation git blame […]

Read More
Git

Git: Use git commit –fixup to Easily Amend Older Commits

- 14.02.26 - ErcanOPAK comment on Git: Use git commit –fixup to Easily Amend Older Commits

Found a typo in commit from 5 commits ago? –fixup marks it for automatic squashing later. Create Fixup Commit: # Find commit hash to fix git log –oneline # abc1234 Add user authentication # def5678 Add email validation ← Want to fix this # Make your fix, then: git add . git commit –fixup def5678 […]

Read More
Git

Git: Use git restore to Unstage Files Without Losing Changes

- 13.02.26 - ErcanOPAK comment on Git: Use git restore to Unstage Files Without Losing Changes

Accidentally staged files you didn’t mean to commit? git restore unstages them without deleting changes. Unstage Specific File: # Staged config.json by mistake git add config.json # Unstage it (keeps changes in working directory) git restore –staged config.json Unstage All Files: git restore –staged . Discard Changes (Careful!): # Unstage AND discard changes git restore […]

Read More
Git

Git: Use git bisect to Find Which Commit Introduced a Bug

- 13.02.26 - ErcanOPAK comment on Git: Use git bisect to Find Which Commit Introduced a Bug

Bug appeared somewhere in last 100 commits but don’t know where? Git bisect does binary search to find the exact commit. Start Bisect: # Mark current commit as bad git bisect start git bisect bad # Mark last known good commit (e.g., a week ago) git bisect good abc1234 Git Checks Out Middle Commit: # […]

Read More
Git

Git: Stash Untracked Files with –include-untracked Flag

- 13.02.26 - ErcanOPAK comment on Git: Stash Untracked Files with –include-untracked Flag

Regular git stash only saves tracked files. New files you created get left behind. Include Untracked Files: git stash –include-untracked # Or shorthand: git stash -u Now new files are stashed too! Apply Later: git stash pop Stash Everything (Including Ignored Files): git stash –all Useful before git clean or switching branches with incomplete work.

Read More
Git

Git: Create Aliases for Common Commands to Save Typing

- 13.02.26 - ErcanOPAK comment on Git: Create Aliases for Common Commands to Save Typing

Tired of typing git status, git commit -am, git log –oneline? Create short aliases. Setup: git config –global alias.st status git config –global alias.co checkout git config –global alias.br branch git config –global alias.cm ‘commit -m’ git config –global alias.lg ‘log –oneline –graph –all’ Now Use: git st # Instead of: git status git co […]

Read More
Git

Git Hooks Automation: Pre-commit Checks That Save Hours of Debugging

- 05.02.26 - ErcanOPAK comment on Git Hooks Automation: Pre-commit Checks That Save Hours of Debugging

Tired of catching bugs in code review? Git hooks automatically validate code before it even reaches the repository. #!/bin/bash # .git/hooks/pre-commit # Exit immediately if any command fails set -e echo “🚀 Running pre-commit checks…” # 1. Check for debugging statements echo “🔍 Checking for console.log statements…” if git diff –cached –name-only | xargs grep […]

Read More
Git

Git Rebase Magic: How to Clean Up Messy Commit History Like a Pro

- 05.02.26 - ErcanOPAK comment on Git Rebase Magic: How to Clean Up Messy Commit History Like a Pro

Your git history looking like a war zone? Interactive rebase transforms chaotic commits into a clean, logical story. The Problem: Spaghetti Commit History # Typical messy history $ git log –oneline a1b2c3d Fix typo in README e4f5g6h Update config again h7i8j9k Another attempt k0l1m2n Revert previous change n3o4p5q Merge branch ‘feature-x’ p6q7r8s WIP: trying something […]

Read More
Git

Git: Find and Remove Sensitive Data from Entire Repository History

- 03.02.26 - ErcanOPAK comment on Git: Find and Remove Sensitive Data from Entire Repository History

Accidentally committed API keys or passwords? Deleting the file in a new commit doesn’t remove it from history. Here’s how to purge it completely. ⚠️ The Problem: # You committed config.json with API key git add config.json git commit -m “Add config” git push # Then realized mistake and deleted it git rm config.json git […]

Read More
Git

Git: Undo Last Commit Without Losing Changes (3 Different Scenarios)

- 03.02.26 - ErcanOPAK comment on Git: Undo Last Commit Without Losing Changes (3 Different Scenarios)

Committed too early or to wrong branch? Here’s how to undo commits without losing your work, depending on whether you’ve pushed or not. Scenario 1: Undo Last Commit (Not Pushed Yet) # Keep changes in working directory (most common) git reset –soft HEAD~1 # Now your changes are uncommitted, ready to re-commit # Use case: […]

Read More
Git

Speed Up Git Operations 10x by Cleaning Up Bloated Repository History

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Speed Up Git Operations 10x by Cleaning Up Bloated Repository History

Is ‘git clone’ taking 10 minutes? Your repository probably has bloated history from large files that were deleted years ago but still exist in Git’s object database. Diagnose the Problem: # Check repository size du -sh .git # If this is >500MB for a code project, you have bloat # Find largest objects in Git […]

Read More
Git

Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)

Accidentally did ‘git reset –hard’ and lost hours of work? Your commits aren’t deleted – they’re just orphaned. Here’s how to find them. The Magic Command – Reflog: git reflog This shows every HEAD movement in your repository, even deleted commits. Output looks like: a1b2c3d HEAD@{0}: reset: moving to HEAD~3 e4f5g6h HEAD@{1}: commit: Added user […]

Read More
Git

The Hidden Cost of Large Commits (It’s Not Code Review)

- 31.01.26 - ErcanOPAK comment on The Hidden Cost of Large Commits (It’s Not Code Review)

Big commits don’t just slow reviews. Real damage Breaks git bisect Makes rollback risky Hides causal relationships Rule One commit = one reason. Mental model If you can’t describe the commit in one sentence, it’s too big.

Read More
Git

Why git pull Sometimes Corrupts Team History (Even Without Conflicts)

- 31.01.26 - ErcanOPAK comment on Why git pull Sometimes Corrupts Team History (Even Without Conflicts)

The issue is not conflicts.It’s implicit merge commits. What happens git pull = fetch + merge That merge commit: Breaks linear history Hides real change intent Makes bisect harder Safer default git config –global pull.rebase true Why this matters Rebase preserves intent, merge preserves state.Teams need intent.

Read More
Git

Recover a Deleted Commit Without Panic

- 30.01.26 - ErcanOPAK comment on Recover a Deleted Commit Without Panic

Commit gone? Not really. git reflog git checkout <hash> Why Git never deletes immediately — it just forgets references.

Read More
Git

Why git pull Is Dangerous in Long-Lived Branches

- 30.01.26 - ErcanOPAK comment on Why git pull Is Dangerous in Long-Lived Branches

git pull = fetch + merge. That merge may silently introduce conflicts. Safer git fetch git rebase origin/main Why Rebase keeps history linear and reviewable.

Read More
Git

Stop Using git pull (Yes, Really)

- 29.01.26 - ErcanOPAK comment on Stop Using git pull (Yes, Really)

git pull = fetch + mergeYou lose control. Better git fetch git rebase origin/main Why Cleaner history Fewer merge commits Easier rollback Rule Explicit is safer than automatic.

Read More
Page 2 of 4
« Previous 1 2 3 4 Next »

Posts navigation

Older posts
Newer posts
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com