Adding script to mail from sourcetree after pushing commit

You want to add a script to run after pushing a commit to a remote repository using Sourcetree.

Sourcetree provides a feature called "Post-commit hooks" that allows you to run a script after committing changes. However, this feature only runs the script after committing changes locally, not after pushing the commit to a remote repository.

To achieve your goal, you can use a combination of Sourcetree's post-commit hook and a remote hook on your Git repository.

Step 1: Create a post-commit hook in Sourcetree

  1. Open Sourcetree and navigate to the repository settings by clicking on the gear icon in the top-right corner.
  2. Click on "Hooks" and then click on "New Hook".
  3. Choose "Post-commit" as the hook type and give it a name (e.g., "Run script after push").
  4. In the "Command" field, enter the script you want to run after pushing the commit (e.g., echo "Script ran successfully!").
  5. Click "Save" to save the hook.

Step 2: Create a remote hook on your Git repository

  1. Log in to your Git repository (e.g., GitHub, GitLab, Bitbucket) and navigate to the repository settings.
  2. Look for the "Hooks" or "Webhooks" section and click on it.
  3. Create a new hook with the following settings:
    • Trigger: "Push"
    • Payload URL: The URL of your script (e.g., https://example.com/script)
    • Content type: "application/json"
  4. Save the hook.

How it works

When you push a commit to your remote repository, the remote hook will trigger and send a request to your script URL. Your script will then run and perform the desired actions.

Note that the post-commit hook in Sourcetree will run after committing changes locally, but before pushing the commit to the remote repository. The remote hook will then run after the commit is pushed to the remote repository.