In order to extend the functionality of git, I recommend you the concept of hooks. They can be put into your Fetch/Pull/Deploy workflow at any desired level.
The most important thing to keep in mind is that they're just working locally. If you want to provide them on your repository provider (like github.com), you can make use of so-named web hooks.
Hooks are available in every cloned repository by default, being set to inactive (e.g. pre-commit.sample
). Active hooks do not have a file extension, hence they are named like post-merge
or commit-msg
.
You can access all hooks by navigating to <root>/.git/hooks
[1].
The usage of hooks is not limited to any OS or GUI Client, you are using git with, as they are run by the git engine and are always executed in a UNIX emulated environment (bash). Nevertheless, i propose you a small list of GUI clients which I have worked with and can recommend.
List of common git GUI Clients (imcomplete and subjective)
- SmartGit
- SourceTree
- gitHub Desktop (see note)
- gitKraken
All of the mentioned clients offer a free-to-use version, the two latters are open-source anyway.
Note: gitHub Desktop does support hooks, but stucks when using certain commands within a hook, like git pull
[2].
Take care of this fact.
Example: pre-commit hook
The following snippet is an example for a pre-commit hook.
At the start, git pull
is performed on the repository and non-ASCII filenames are allowed.
Basically this hooks checks all staged files against a file name pattern (*.sql), renames them and adds some bits to their content, before staging them again.
The content search and renaming is performed efficiently by the grep
command, while using regular expressions.
Potential error messages along with other information are piped to the default error output, which is usually a message box (When using a GUI client), otherwise to the shell.
Hooks within submodules
If your main repository has included submodules and you want to access their hooks, your git
folder is still on root level of your file structure. You can find the hooks therefore below <root>/.git/modules/hooks
.
Sources
[1] git-scm.com: Customizing git hooks
[2] github.com: Pre-commit hooks won't work with gitHub Desktop