Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

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
Git

Git: Fix a Pre-Commit Hook That Silently Doesn’t Run After a Fresh Clone

- 27.09.26 - ErcanOPAK

🔀 The Hook Everyone Assumed Was Already Installed

A hooks/ folder committed to the repository (containing a pre-commit script the team relies on to catch lint errors, secrets, or formatting issues) does absolutely nothing on its own – git only ever executes scripts from .git/hooks, which is a local, per-clone directory that is never populated by cloning the repository, since .git/ itself isn’t tracked content. A brand new clone has an empty .git/hooks folder (aside from the .sample files git ships by default) regardless of how carefully the team’s actual hook script is maintained in the repo.

🔎 The Problem

# Repo layout, carefully maintained and reviewed like any other file:
#   hooks/pre-commit        <- the team'"'"'s actual lint/secret-scan script
#   scripts/setup-hooks.sh  <- copies hooks/* into .git/hooks (never run)

git clone git@example.com:team/project.git
cd project
# .git/hooks/ contains only git'"'"'s own *.sample files right now.

git add .
git commit -m "quick fix"
# Commits instantly - the team'"'"'s pre-commit script never ran, because
# nothing installed it into .git/hooks for THIS clone. No error, no
# warning: git simply has no hook registered at all for this event.

✅ Fix: Install Hooks Automatically, Don’t Rely on a Manual Step

  • core.hooksPath (git config core.hooksPath hooks) points git directly at a tracked, versioned folder instead of .git/hooks – this is the most reliable fix, since it removes the copy-into-.git step entirely and makes the hook active the moment the config is set, with no separate install script to forget to run.
  • Where core.hooksPath isn’t an option (an older git version, or a tool like Husky already managing hooks a specific way), a documented setup step run immediately after cloning – and ideally automated via a package manager’s postinstall script – closes the gap, as long as it’s something that actually runs rather than something a README merely asks a developer to remember.
  • A CI pipeline step that independently re-runs the same lint/secret checks the pre-commit hook was meant to catch is the real safety net – a hook that silently isn’t installed on one developer’s machine is a productivity gap, but CI catching the same issue before merge is what actually prevents it from reaching the main branch.

⚠️ Why Nobody Notices Until Something Slips Through

  • Everyone who set up their local environment before the hook was introduced, or through a process that happened to install it, has it working – so the bug is invisible to the very people most likely to be asked whether hooks are working, since their own setup is the one place it isn’t broken.
  • This surfaces almost exclusively through a NEW team member’s first few commits, or a machine reimage/fresh clone by an existing member – exactly the situations where nobody is specifically checking whether hooks got installed, because installing them was never presented as a distinct, necessary step in the first place.

A pre-commit script sitting in the repository is documentation of intent, not an active hook – git only listens to what’s already inside .git/hooks, and cloning never puts it there for you.

— Version Control Tip

Related posts:

Git: Fix git status Taking Several Seconds on a Large Repo Because the Built-In Filesystem Monitor W...

Git: Fix git status Taking Several Seconds on a Large Repo Because the Built-In Filesystem Monitor W...

Git: Use Rebase for Clean Commit History

Git: Use Rebase for Clean Commit History

Git: Use Git Add to Stage Changes for Commit

Git: Use Git Add to Stage Changes for Commit

Views: 7

Post navigation

Git: Fix a Bisect Session That Keeps Landing on Commits You Already Ruled Out
Photoshop: Fix a Vector Mask That Distorts the Moment You Free Transform Its Layer

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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