Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

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

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Git

Git: Fix a Hook Script Getting Skipped After a Repo Move

- 24.11.26 - ErcanOPAK

🔀 Git: Fix a Hook Script Getting Skipped After a Repo Move

Git’s local hooks live under .git/hooks, or wherever core.hooksPath points, a location deliberately never cloned, copied, or carried along by a repository move, because hooks are local machine configuration rather than versioned repository content. Moving a repository’s working directory to a new path on disk, or recreating it via a fresh clone on a new machine, silently leaves every previously-configured hook behind, since there was never any linkage between the hook files and the repository’s tracked content for a move operation to preserve.

🔎 The Problem

# Original setup: hook manually placed, works fine
cp pre-commit-lint.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

# After `mv ~/old-path/repo ~/new-path/repo` (or a fresh clone
# of the same remote on a teammate's machine):
# .git/hooks/pre-commit never existed there to begin with -
# commits silently skip the lint check with no warning at all

✅ Fix: Version the Hooks, Don’t Just Install Them Locally

  • Store hook scripts as tracked files inside the repository, such as a /githooks directory, and set core.hooksPath to point at it, so every clone of the repository gets the same hooks automatically instead of relying on a manual copy step per machine.
  • Add a setup script that every contributor runs once after cloning, which symlinks or copies the tracked hook files into .git/hooks, documenting the one manual step that core.hooksPath would otherwise eliminate.
  • Verify active hooks with ls -la .git/hooks or git config core.hooksPath right after any repository move or fresh clone, since a missing hook produces no error on the commits that skip it, only its absence, which is easy to miss.

🚨 Why This Is Dangerous

  • A pre-commit hook enforcing lint rules or secret scanning that silently stops running after a repo move means every commit from that point on skips the exact safety check the team was relying on, with nothing in the commit history showing it was ever bypassed.

A hook isn’t part of your repository’s history — it’s part of whichever machine happened to have it installed, and a move takes you to a machine that never did.

— Version Control Tip

Related posts:

Git: Fix a Submodule Stuck on a Detached Head After a Pull

Git: Fix a Submodule Stuck on a Detached Head After a Pull

Git: Fix a .gitattributes Line Ending Rule That Only Takes Effect on Files Checked Out After It Was ...

Git: Fix a .gitattributes Line Ending Rule That Only Takes Effect on Files Checked Out After It Was ...

Git: Fix git log Missing Commits You Know Exist Because a Shallow Clone's --depth Cut the History Sh...

Git: Fix git log Missing Commits You Know Exist Because a Shallow Clone's --depth Cut the History Sh...

Views: 10
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Network Speed Monitor Windows Application v2.5.2
The AI Prompt That Turns a Vet Bill Into an Insurance Claim Draft

Leave a Reply Cancel reply

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

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

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

Social

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