Jango
Jango

Reputation: 199

Is there a git hook for `git add`?

I been researching but haven't had any exact luck on:

  1. knowing where exactly to look for these answers
  2. what to search on google beyond variations of "Is there a git hook for git add?"

So, here I am, wondering if there is a way I can have a pre-add, during-add, or post-add hook to add a linter. My work currently has one for post-commit which is pretty annoying because I have to amend each time something changes.

Upvotes: 6

Views: 687

Answers (2)

Gonzalo Matheu
Gonzalo Matheu

Reputation: 10064

You could use a git alias:

First, to add a pre-add command, define the alias ladd (linter+add):

git alias.ladd '! your-linter-command; git add'.

Then you can use as the add command: git ladd

PS: Pro Git book is the place to look for git information.

Upvotes: 2

karmakaze
karmakaze

Reputation: 36134

There is a pre-commit hook which isn't during add but during commit. It is however run before other hooks during the commit process. It even runs before editing the commit message.

If it's for yourself you could also just create an alias and get in the habit of using that instead of plain add.

Upvotes: 1

Related Questions