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
49
votes
3 answers

Handle multiple pre-commit hooks

I have a need to use multiple pre-commit hook scripts. Not sure how to handle them. Should all of them be combined into one single large pre-commit script ? if not, how to handle multiple pre-commit scripts ?
karthik101
  • 1,619
  • 4
  • 17
  • 23
46
votes
4 answers

change default git hooks

Not sure if this is possible in git (I haven't found it but I may be using the wrong vocabulary in my searches), but it be would useful to be able to modify and enable hooks as the defaults for all new repositories (at the time of creation I mean)…
rplevy
  • 5,393
  • 3
  • 32
  • 31
45
votes
1 answer

github server-side git hooks (i.e. pre-commit and post-commit)

I've looked around the answers on SO, and the web, and I can't see anything on how to set up a server-side git hook on github (as opposed to webhooks). Is there a way to do this? Or alternatively, is there a way to set it up so that .git/hooks is a…
Marcin
  • 48,559
  • 18
  • 128
  • 201
41
votes
5 answers

git hooks : is there a clone hook?

We want to store some meta-information about the commit in an external database. During a clone or a checkout, this database should be referred and we copy the meta information to a file in the repo which is cloned. The database is required rather…
maxmelbin
  • 2,045
  • 3
  • 21
  • 29
40
votes
3 answers

Commit in git only if tests pass

I've recently started using git, and also begun unit testing (using Python's unittest module). I'd like to run my tests each time I commit, and only commit if they pass. I'm guessing I need to use pre-commit in /hooks, and I've managed to make it…
Skilldrick
  • 69,215
  • 34
  • 177
  • 229
39
votes
2 answers

How to execute a command right after a fetch or pull command in git?

I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the GHC hackers included a script sync-all that, when…
fuz
  • 88,405
  • 25
  • 200
  • 352
38
votes
1 answer

Find Git branch name in post-update hook

I'm executing a programme to alert CruiseControl each time an update is sent to our remote repository. I'm using a Git post-update hook for this. It would be great if I could find out which branch had been committed so I could use that to inform…
user489998
  • 4,473
  • 2
  • 29
  • 35
37
votes
2 answers

How to set up a Git hook so that after pushing to ssh://peter@foo.com/~/bar.com.git, it will go to ~/bar.com and do a git pull?

I was advised to set up on a remote server foo.com/~/bar.com # live webpage content foo.com/~/bar.com.git # a bare repo so, from my local machine, I can do a git push and it will push to foo.com/~/bar.com.git on the remote machine (the…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
36
votes
1 answer

How do I react to new tags in git hooks?

I'd like to set up a git hook that creates a CDN-style directory structure based on incoming tags. So, for example, if the last tag in the local repository is "v1.2.1" and I pull a commit with "v1.2.2", it should see the new tag and clone the…
futuraprime
  • 5,468
  • 7
  • 38
  • 58
35
votes
2 answers

git commit in pre-push hook

I have added something like that in pre-push hook: gs0=$(git status) pip-dump gs1=$(git status) if [ "gs0" != "gs1" ] then git commit -m "pip-dump" fi (this is updating my pip requirements file) It seems that the push is not pushing the new…
lajarre
  • 4,910
  • 6
  • 42
  • 69
34
votes
4 answers

Run Create-React-App Tests not in Watch Mode

I have a project created using Create-React-App. I am looking to add in a precommit hook to run our linter and tests with the pre-commit package. "pre-commit": [ "precommit-msg", "lint", "test" ], However, since the test script runs by…
Yuschick
  • 2,642
  • 7
  • 32
  • 45
34
votes
4 answers

Git receive/update hooks and new branches

I have a problem with the 'update' hook. In the case of a new branch, it gets a 0000000000000000000000000000000000000000 as the 'oldrev'. And I don't know how to handle that case. We have the requirement, that every commit message references a valid…
marc.guenther
  • 2,761
  • 2
  • 23
  • 18
33
votes
3 answers

Chaining git hooks

As many of you probably know, there can be only one hook type in git. If two update hooks need to be evaluated. The git admin is left with two unmanageable solutions: Merge the hook scripts together Manually chain them with an exec I am looking…
Olivier Refalo
  • 50,287
  • 22
  • 91
  • 122
32
votes
1 answer

Git hooks : applying `git config core.hooksPath`

I have a git repository with a pre-commit hook set up : my-repo |- .git |- hooks |- pre-commit # I made this file executable Until there, everything works. The hook is running when I commit. ================================= I now run…
Nicolas Marshall
  • 4,186
  • 9
  • 36
  • 54
31
votes
7 answers

Append ticket number using git commit hooks?

So my branch is named after bugtracker ticket number, something like "issue-1234", and we have a convention to always write down ticket number in commit message. I'm wondering if it's possible to append the ticket number in commit message…
EnToutCas
  • 1,297
  • 2
  • 15
  • 20