Some useful hooks for git-flow (AVH Edition).
- Prevent direct commits to the master branch.
- Prevent merge marker commits.
- Automatically bump versions when starting a release or hotfix. Versions are generated, written to file and committed.
- Automatically specify tag messages.
git clone
this repository somewhere on your disk.- Remove the
.git/hooks
directory in your repository. - Symlink the git-flow-hooks directory to
.git/hooks
in your repository. - Optionally copy
.git/hooks/modules/git-flow-hooks-config.sh.dist
to.git/git-flow-hooks-config.sh
and set values according to your wishes.
OS X doesn't support sort -V
, which is used to sort git tags by version number, which in turn is needed to correctly bump versions.
On OS X you can install coreutils (using MacPorts or Homebrew), after which gsort -V
can be used. If it's located in /opt/local/bin/gsort
we will pick it up automatically. Otherwise we fall back to /usr/bin/sort
.
Optionally you can use the configuration option VERSION_SORT
to point to a different command.
- Run
git pull
in the git-flow-hooks directory.
That's it, all your repositories that have symlinked git-flow-hooks will use the latest version.
Copy the file .git/hooks/modules/git-flow-hooks-config.sh.dist
to .git/git-flow-hooks-config.sh
and change whatever you like. This is completely optional.
git-flow (AVH Edition) has some useful configuration options too. See its wiki for a complete list.
Or you can type git flow <command> [<subcommand>] --help
.
If git flow release start
and git flow hotfix start
are run without a version, the version will be bumped automatically. Releases will be bumped at the minor level (1.2.3
becomes 1.3.0
), hotfixes at the patch level (1.2.3
becomes 1.2.4
). The hooks will look at the git tags to find the version to bump. If no tags are found, it looks for the version-file. If that isn't found, it assumes the current version is 0.0.0
.
Alternatively you may use patch
, minor
and major
as version. A bump of that level will take place.
If the commands are run with version, that version will be used (no bumping).
If you want tag messages to be automated (you won't be bothered with your editor to specify it), use the following configuration options:
$ git config gitflow.hotfix.finish.message "Hotfix %tag%"
$ git config gitflow.release.finish.message "Release %tag%"
If you like, you can change the tag-placeholder (%tag%
in the example above) in the git-flow-hooks configuration.
git-flow-hooks is published under The MIT License, see the LICENSE file.
Note that these hooks are built for git-flow (AVH Edition) by Peter van der Does, which has its own licenses.
The scripts for preventing master and merge marker commits are based on git-hooks by Sitebase.