git-clone and post-checkout hook
Very well, now, considering the following:
- git hooks: Detect which system is running
- Git pre-commit hooks only for a specific subfolder?
- Is it possible to accept user input as part of a remote git post-receive hook?
- git tracking one file changes
- Git pre commit and pre push hook for sonar runner
- How to get a git diff for a file in a pre-receive hook between the current HEAD and the newest file from the push?
- you don’t have a local repository before a
- hooks are not synced between remotes
hooks stored in a custom template directory used with(that is actually not true as stated by Jefromi in his answer, but the hook is still not executed)
--templateare copied non-executable and therefore not executed after
It seems impossible that a
post-checkout hook ever gets executed after a
git clone. Still, the
githooks man page at http://git-scm.com/docs/githooks explicitely states a way to avoid it being executed, and also parameters passed in case it is executed, which would indicate it is possible to execute a custom hook after a
So, how is it possible? I am obviously missing something here.
2 Solutions collect form web for “git-clone and post-checkout hook”
I suppose you could make a custom installation – rename the hooks in
.../share/git-core/templates/hooks to remove the
You could also make a template directory full of symlinks to a hooks directory inside the repository, (e.g.
post-checkout -> ../../hooks/post-checkout). Then if the cloned repo contained that particular hook, it’d get executed.
You’re right, though, in most cases it will not happen.
Edit: I just tested it, and the
--template option does appear to preserve permissions, so that’s a much more straight-forward way to make it happen. What’d you see to indicate that it stripped that bit?
The final say on versions: You’re looking at documentation online for a newer version of git than you’re using. This feature was added in dfa7a6c (clone: run post-checkout hook when checking out); git describe says this wasn’t included until v1.6.2-rc2.
From the githooks documentation:
When git-init is run, a handful of example hooks are copied into the
hooksdirectory of the new repository, but by default they are all disabled. To enable a hook, rename it by removing its
This initialization takes place as part of creating a clone—note the call to
$ cat /tmp/my-git-template/hooks/post-checkout #! /bin/bash echo "Hello from $0" $ git clone --template=/tmp/my-git-template file:///tmp/repo.git my-clone Initialized empty Git repository in /tmp/my-clone/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. Hello from .git/hooks/post-checkout