How to run bash script after git push

I wanted to know how to execute a bash script in the local repo after pushing to github.

The bash script is located in the root of the folder. It can be moved around depending on where it is being called I guess.
I have looked into git hooks but there is no post-push hook and I don’t understand the other hooks very well.

  • git post-commit hook not executed
  • How to create alias for git bash to make fast cd through directories
  • git-filter-branch to remove strings, but where strings contain $ ' \ and other characters
  • Error authenticating Github using Travis CI
  • Git alias for fast commit with optional text
  • How can I display commit's position in the history relative to tags (and branches)?
  • I’m trying to call a jenkins build after the push. I have looked into ways of notifying jenkins after a push with post-receive url etc on github but nothing seems to work for me.

    This is the script I’m trying to run:

    #!/bin/bash/
    java -jar jenkins-cli.jar -s http://localhost:8080/ build Test
    

    Thanks!
    Varun

  • Configuring SSH keys for git to use when not in Git Bash
  • Create archive of modified files in GIT via batch file
  • git detects renames/moves in our Java project poorly - what to do?
  • Why does Git remember and use a conflict resolution from an aborted rebase without asking me?
  • Git unknown switch 'C'
  • Best way to use npm and git?
  • 2 Solutions collect form web for “How to run bash script after git push”

    This is fairly easy. There is a script ready to run. You will have to modify .git/hooks/post-commit to find the script you need to run.

    mv .git/hooks/post-commit.sample .git/hooks/post-commit
    vim .git/hooks/post-commit
    

    I found this at: git-scm.com: Git Hooks

    If there is no .git/hooks/post-commit.sample file, not a problem, just create .git/hooks/post-commit from scratch, for example:

    #!/bin/sh
    echo look at me I am the post-commit script
    pwd
    # call the script you want
    

    Remember to make the script executable with chmod +x.

    Do a test commit and you should see the output of the script, right before the regular output of the commit.

    I ended up using this answer here.

    https://stackoverflow.com/a/3812238/1490695

    Hope this helps!

    Git Baby is a git and github fan, let's start git clone.