If you need to execute a script after a git pull
on the client side (your machine), then a there is no reliable solution.
The post-merge client-side hook (mentioned here) won’t be triggered by every pull (for instance, not in a pull rebase, not in case of fast-forward merge)
So an alias wrapping both commands remains a possible workaround.
Original answer (2011)
If you need that on the server side, where you would checkout the bare repo and pull from a working tree (on the server) after each push to a bare repo (on the server):
A post-receive
or post-update
hook is generally used for this kind of task, executed after each push.
The difference between the post-receive and post-update hooks is in the arguments: a post-receive
will get both the old and the new values of all the refs in addition to their names.
The missing piece is: where that hook executes itself?
The blog post “Missing git hooks documentation” from (a great) SO contributor Mark Longair sheds some light on this:
the current working directory will be the git directory.
- So, if this is a bare repository called “
/src/git/test.git/
”, that will be the current working directory
– if this is a non-bare repository and the top level of the working tree is “/home/mark/test/
” then the current working directory will be “/home/mark/test/.git/
”Chris Johnsen details in his SO answer: “If
–-git-dir
orGIT_DIR
are specified but none of-–work-tree
,GIT_WORK_TREE
andcore.worktree
is specified, the current working directory is regarded as the top directory of your working tree.”In other words, your working tree will also be the current directory (the “
.git
” directory), which almost certainly isn’t what you want.
Make sure your hook/post-receive
script, once created and made executable, sets the GIT_WORK_TREE
at the right path, in order for your ./sync-all pull
to be executed in the right directory (i.e. not “xxx.git
” one).