Questions tagged [githooks]

Git hooks are scripts that are executed upon certain Git events. Events include, but are not limited to, pre- and post-commit and pre- and post-rebase on the client-side, and post-receive-commit on the server-side. No need to use the tag Hooks when using the tag Githooks. Maybe used in combination with tag Webhooks

What is it?

Git hooks are scripts that are executed upon certain Git events. Events include, but are not limited to, pre- and post-commit and pre- and post-rebase on the client-side, and post-receive-commit on the server-side. Hooks can be written in most any scriptable language, including Ruby, Perl, Bash, and shell.

Related tags

  • Git hooks are prohibited on most commercial Git services like GitHub, Bitbucket or GitLab, for security reason. Those propose which are only able to send a JSON payload to a URL (like a push).
  • Use for other hooking mechanisms in the source management or build process that do not rely on Git hooks.
  • Use for webhooks used on GitHub as an alternative to Git hooks.

Useful Links

1768 questions
96
votes
5 answers

getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo

I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best. I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a web server. I've tried to pattern it after this…
Ty W
  • 6,694
  • 4
  • 28
  • 36
96
votes
10 answers

Can a Git hook automatically add files to the commit?

I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit. How would I go about this? I've tried this as a pre-commit hook, but no…
Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
92
votes
13 answers

How can I automatically deploy my app after a git push ( GitHub and node.js)?

I have my application (node.js) deployed on a VPS (linux). I'm using git hub as a repository. How can I deploy the application automatically, on git push ?
Advanced
  • 1,457
  • 2
  • 13
  • 12
91
votes
9 answers

Why is my Git pre-commit hook not executable by default?

If you see the accepted answer in: Aggregating and uglifying JavaScript in a Git pre-commit hook, you'll see that I had to do a chmod +x on my pre-commit hook to get it to work. Why is this not executable by Git by default?
Josh Smith
  • 14,674
  • 18
  • 72
  • 118
81
votes
8 answers

Git remote/shared pre-commit hook

With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on all clones of it?
Samer Buna
  • 8,821
  • 9
  • 38
  • 55
80
votes
8 answers

Is there a way to lock individual files or directories on fork when using git?

We are a team of 60+ developers working on the same product and are moving from SVN to Git and GitHub. We have a process in SVN where in individual files are locked and whenever a developer wants to commit code, he needs to get it unlocked by the…
Karthick S
  • 3,204
  • 6
  • 36
  • 52
78
votes
6 answers

Tracking changes to hooks in .git/hooks

Is there a way to track git hook changes? I have three hooks that only show up on my machine, not when my other developers fetch. Trying to git add doesn't work.
Hans
  • 3,403
  • 3
  • 28
  • 33
74
votes
7 answers

Local executing hook after a git push? (post-push)

I've looked at the githooks manpage but unless I'm missing something I don't see an option for local, post-push git hooks. I'd like to have one that updates the api docs on my web server (for which I already have a script) after I push the master…
scotchi
  • 2,359
  • 2
  • 19
  • 21
69
votes
3 answers

When I "git push" git now says "Create pull request for ...". Why?

I am making changes to a project in a branch that, so far, is known to no one else but me. However, starting recently, when I git push to this project, I now receive this as part of the response: remote: Create pull request for <
Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
61
votes
3 answers

How would I write a pre-merge hook in Git?

The question says it all. Is there a way to perform an action before a merge? I'm guessing there's a way to make use of a pre-commit hook, but I'm not quite sure.
joshin4colours
  • 1,656
  • 4
  • 16
  • 27
56
votes
4 answers

Is there a way to trigger a hook after a new branch has been checked out in Git?

Is there a way to trigger a hook after a new branch has been checked out in Git?
netflux
  • 3,648
  • 6
  • 37
  • 40
55
votes
9 answers

Git pre-commit hook is not running on Windows

I'm just starting to look into Git hooks, but I can't seem to get them to run. I set up a local repository, so there is now a '.git' directory in my project folder. I have added a '.cmd' file into the C:/path/to/my/project/.git/hooks directory named…
user1578653
  • 4,888
  • 16
  • 46
  • 74
54
votes
4 answers

Post Commit Hook Not Running

My post commit hook is not running after git. I have verified that the hook does work if I just run it from the terminal. The code in the hook is: #!/bin/sh #.git/hooks/post-commit # An example hook script that is called after a successful #…
Dave Long
  • 9,569
  • 14
  • 59
  • 89
51
votes
5 answers

black as pre-commit hook always fails my commits

I'm trying to use pre-commit to manage Black as a Git pre-commit hook, but I must be doing it wrong. In my pre-commit config file I have: - repo: https://github.com/psf/black rev: 19.3b0 hooks: - id: black What I'm expecting to…
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
49
votes
10 answers

Running PowerShell scripts as git hooks

Is it possible to run PowerShell scripts as git hooks? I am running git in a PowerShell prompt, which shouldn't make any difference, but I can't seem to get them to work, as the hooks are named without extensions, and PowerShell needs (AFAIK) the…
Erick T
  • 7,009
  • 9
  • 50
  • 85