Useful git hooks

Git hooks is a nice way to do extend git capabilities.

I decided to create some of them which helps in different day-to-day situations

I have a repository http://bitbucket.org/mnaoumov/githooks/ where you can get all of them.

So far two hooks are implemented which handles the situation when you do pull from a repository having some local commits and this ends up with ugly merge commit such as

Merge branch ‘test_merge_pull’ of ssh://bitbucket.org/mnaoumov/githooks into test_merge_pull

These commits make git history non-linear and difficult to read.

My hooks handle this situation showing the dialog

Pull merge commit

Unfortunately git does not have pre-merge hooks and that is why I had to use post-merge and then rollback the changes.
If merge had conflicts the only hook is applied is after you fix the conflicts and do commit. But in this case post-merge is not called and I have to use post-commit instead.

TODO list for other Hooks

  • You can often have different releases branches such as release.1.0, release.2.0 and master for a future release.

    When you make some change in release.1.0 you should merge it with release.2.0 and then release.2.0 with master.

    My idea is to write a hook which will allow only such merges and block all others.

  • Hook which allow rebase only local branches and block rebase of already published branches
  • Hook which will block incorrect ‘hard reset’ pushes (see for more details). Unfortunately git does not have no pre-push hooks which can be used on a client-side so we have to have a server-side hook.
  • Hook that will check that all your commit messages prefixed with corresponding TFS work item ID

Useful git hooks – Part 2

Advertisements

About mnaoumov

Senior .NET Developer in Readify
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

3 Responses to Useful git hooks

  1. Pingback: Useful git hooks – Part 2 | mnaoumov.NET

  2. Pingback: Useful git hooks – Part 3 | mnaoumov.NET

  3. Pingback: WTF: PowerShell 3 & Cygwin | mnaoumov.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s