53

Possible Duplicate:
Local executing hook after a git push?

git has a number of hooks that can call scripts near certain events.

Is it possible to setup a git hook in my working repository that executes something locally after I push to a remote branch? If so which hook is it?

Community
  • 1
  • 1
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

1 Answers1

52

The list of hooks in man githooks is complete. There is no post-push hook. There are hooks which run in a repository after someone's pushed into it (i.e. for putting in the central repository), but nothing is triggered in the repository that you pushed from.

If there's a common task you need to do after pushing, you could make an alias which pushes then does that.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • 11
    That's too bad. We're behind a firewall so such a hook would have been great. – dkinzer Apr 26 '12 at 23:27
  • 3
    I also need that kind of hook to close the VPN connection that was opened with pre-push. – tiktak Jan 22 '15 at 13:50
  • @tiktak for security reasons, you should probably implement a timeout anyway... (that being said, I would also have loved such a hook) – Guy Sep 01 '16 at 06:28
  • 2
    Could you mention some of the hooks you mentioned? "hooks which run in a repository after someone's pushed"? I need one of them – Mohammed Noureldin Jul 06 '17 at 14:21
  • 1
    they are referring to post-receive on the server side which runs after it has been pushed to. – vextorspace Aug 10 '17 at 20:11
  • Just checked for git v2.33.0 - `man githooks` shows there MANY more hooks than those seen here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks But, there's not post-push hook. (I didn't dig into all the hooks in exquisite detail, so it's not impossible that it can't be hacked together). – Devin Rhode Oct 01 '21 at 19:46
  • One hack could be a pre-push hook that sets up some sort of "listener" which polls for some sort of data you get from git status, and then can run something once it see's the push has been successful. – Devin Rhode Oct 01 '21 at 19:47
  • 3
    If it's possible to "overwrite" the default `git push` command, or create an alias `git psh`, you could effectively create a post-push hook, since these commands could do whatever they want. – Devin Rhode Oct 01 '21 at 19:49
  • 1
    I have an alias `alias gh='git push heroku && sh test/test.sh serverhe'` to execute a bash script after a push to heroku. – Timo May 14 '22 at 09:17