Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to hook all ways of creating git repo? So I can run script when repo is cloned, initialized… (are there any other ways, except moving/copying folder?).

My intention is to track all repos, so I don't need to go through all dirs to run some action (mainly git status as I sometimes forget to commit changes and git gc --auto).

share|improve this question

Hooks are (currently) exclusively configured per-repository, so there can be no active hooks before a repository is created.

If you just want to initialize some repository specific settings identically for all new repositories you might be able to use the repository template mechanism.

By using your own template you can

  • install activated hooks (by providing a <template‑dir>/hooks/<hook‑name> file),
  • set configuration variables (by providing a <template‑dir>/config file), and
  • configure per-repository exclude rules or attributes (by providing a <template‑dir>/info/exclude or <template‑dir/info/attributes> file).

Any configuration file that lives in a .git directory can be placed in a template to serve as the initial copy for that file in new repositories initialized from the template. I suppose you could even provide initial objects and refs.

Once you have a template directory made up with your customizations you must tell git init and git clone where to find it. This can be done explicitly with the --template option (Git 0.99.4 or later), or implicitly with the GIT_TEMPLATE_DIR environment variable (Git 1.5.0 or later), or implicitly by setting the init.templatedir configuration variable in the “global” (per-user) or “system” Git configuration files (i.e. ~/.gitconfig or /etc/gitconfig (varies by installation); Git 1.7.1 or later).

share|improve this answer
Thank for answer, but it is not what I was looking for: I want to track all repos, I added line about my intention to the question. – tig Jul 16 '10 at 9:40

You cannot "track" git repos (as in "ask some central referential the list of currently active git repo).
Each git repo is independent from another.

Two solutions might be considered:

  • a git template as in Chris's answer, with one of the client-side hooks able, on the first use, to register the git repo in some "central" file.
    That file would then be read by an external script (external to git), in order to make the relevant git status or git gc that you want.

  • if all your git repos are declared under the same common directory, you could declare a global parent git repo and add all the sub-repos as submodules.
    Since git1.7.0, git status knows when a submodule contains uncommitted changes.

share|improve this answer
Note: on git submodules, there is a fairly complete introduction on this: – VonC Aug 2 '10 at 7:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.