Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to run a git command as a custom action?

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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

2 votes
Answer accepted
Aseem Parikh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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.

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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.

Aseem Parikh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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

Aseem Parikh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

Awesome! I'm glad you got that working

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2013

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).

Mike Friedrich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2015

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.

0 votes
Rajavanya Subramaniyan May 9, 2015

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events