How to run a git command as a custom action?

I want to set up a custom action to run a particular git command.

I've tried putting "git" in the "script target", which errors with no explanation. I've tried putting "cmd" in the script target with "/C git" in the "Parameters" and gotten a "'git' is not recognized" error.

I use SourceTree's embedded Git on Windows (8.1). I'm sure there's a simple way to do this, but I can't find any good resources.

2 answers

1 accepted

Hi Seth,

Custom actions can run arbitrary scripts as well as git commands. Since you're using the embedded git executable, it would probably be best if you put that command into a .bat file and use that .bat file as your script target.

The embedded Git isn't registered on my Windows %Path%, so I'm not sure I can run it from a batch file either without knowing what the path to the executable is.

It looks like the embedded Git is run inside mingw, so it may not even be possible to run via "cmd".

In other words, I know it can run arbitrary scripts and how to do that. I can't figure out the more obvious usage, which would be custom git commands.

You can add git to your path or specify the path to git.exe in your .bat file.

You should be able to find git.exe here:

%USERPROFILE%\AppData\Local\Atlassian\SourceTree\git_local\bin

Awesome! I'm glad you got that working

That's the path I needed. It also works to specify that full path to cmd \C.

For anyone interested, I created a custom action to set the executable bit (for scripts stored in Git). In windows I set the script target as "cmd" and the parameters as "/C %USERPROFILE%\AppData\Local\Atlassian\SourceTree\git_local\bin\git.exe update-index --chmod=+x $FILE" (omit the quotes).

It would be nice if sourtree would add the correct git-path itself (based on its internal/external selection) in its own process before executing custom actions. That way its much easier to giy in custom actions.

I added an example of how to setup "git clean" using custom actions in Sourcetree
http://githubtraining.com/custom-actions-in-sourcetree-example-setup/

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

242 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot