0

Why is the .git repository not part of any branch? When I create new git hooks are they not tracked within git itself?

Daniel Marchand
  • 584
  • 8
  • 26

1 Answers1

2

It is a special directory that Git ignores in a repository, as it contains the information about the repository itself.

So no, hooks that you place is .git/hooks are not tracked within your project.

However, you can for example do the following:

In your project, create a hooks directory and place them here. Then, in .git/hooks create the hooks a symbolic links pointing towards those in your repo. It'd look as follow:

├── .git
│   ├── config
│   ├── HEAD
│   ├── hooks
│   │   └── pre-commit -> ../../hooks/pre-commit
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
└── hooks
    └── pre-commit

So you can keep them versioned within your project.

If you want to have more global hooks to use across repositories, you can use templates, I wrote an article about how to set it up: https://www.ghislain-rodrigues.fr/articles/git-hooks-template.html

padawin
  • 4,230
  • 15
  • 19