Join the chat at

Build Status   Dependancy Status   NPM Version

Github Web Hook Listener in Node.js

Why fish? What receives a hook?


$ gitfish help
              Usage: gitfish [forever options] action
               Gitfish Actions
                 config   build initial config file
                 start    start gitfish
                 help     show this message
               Daemonized Actions
                 stop     stop gitfish (when daemonized)
                 restart  restart gitfish (when daemonized)
                 status   status of gitfish (when de
               Optional Gitfish Options
                 --daemonize : start gitfish daemonized
                 --config    : default is `$CWD/config.json`
                 --port      : override port from config
                 --token     : override token from config
               Supported Forever Options
                 --logFile [file] : forever log file location # default: /tmp/gitfish.log
                 --outFile [file] : stdout file location      # default: forever log file
                 --errFile [file] : stderr file location      # default: forever log file
                 --pidFile [file] : pid file location         # default: /tmp/
                 --max     [n]    : max restarts on error
                 --plain          : disable command line colors
                 --verbose        : verbose forever output
               What is forever?

Usage Examples

$ npm install git-fish
              $ gitfish config
              Listener port? [8000]
              Security token? [secret]
              Hook endpoint? [script] /foo
              Hook script? [CWD/script.js]
              Hook branch filter?
              Saved configuration to /home/jmervine/config.json
              $ cat config.json
                "port": 8000,
                "token": "secret",
                "foo": {
                  "script": "/home/jmervine/script.js"

Configuration note:

script can be anything; ruby, bash, python, etc. It doesn't have to be a node script.

Real World Config Example

Important Note:

script path must absolute and the script must be executable.

                "port": 8001,
                "token": "shhh_do_not_tell_anyone",
                "prod": {
                  "script": "/home/me/",
                  "branch": "master" // optional branch matcher
                      // "branch" can also be an array of branches:
                      // e.g. `[ "master", "develop" ]`
                "dev": {
                  "script": "/home/me/",
                  "branch": [ "release", "develop" ] // optional branch matcher

Where /home/me/ is something like:

#!/usr/bin/env bash
              cd /path/to/mysite
              # For safety, you can stash any changes, although best practice says
              # there shouldn't be any here.
              # git stash
              git checkout master
              git pull
              make restart

And your post commit hooks would be:



Articles on git-fish

Github Webhooks with git-fish

I wrote git-fish – a Github Webhook listener – to provide a simple and modular method for executing an autodeployment on when adding or updating a post. I designed it to as simple and as modular as possible. While written in Node.js, I tend to use it execute simple bash scripts, like the deployment script:


cd /home/jmervine/
make deploy/soft

With this combination, I can use [Github] as my psudo-CMS, to create and update posts and when I save an addition or change, it becomes visable on the site in seconds (including, updating code and purging cache).

For detailed information on setting up and using git-fish or my other see my git-fish project page.