How do you open SourceTree from the command line?

Installing the SourceTree Command Line Tools will provide you with the stree command. This will allow you to open the current directory in SourceTree.

sourcetree commandline tools

You can also specify a particular path to a repo

stree ~/my-repo-in-another-folder

If installing command-line tools isn't an option for whatever reason, you can also do the following:

open -a SourceTree path-to-file

and maybe set up an alias in .bashrc or .zshrc

alias sourcetree='open -a SourceTree'

For those who are using SourceTree 3

alias sourcetree='open -a SourceTree\ 3'

The answer by loeschg may not work; some people get an error referring to their system logs and cannot install the command line tools. There is an open issue about this.

A workaround is found here. Use:

ln -s /Applications/SourceTree.app/Contents/Resources/stree /usr/local/bin/

This will create a symbolic link to the stree binary and put it in /usr/local/bin. Make sure that directory is on your path: which stree should result in /usr/local/bin/stree. If it does not, then add it to your PATH manually or use echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile, which does it for you (restart your shell to reload the PATH variable).

On the above-mentioned issue's page, another workaround that I didn't test was posted: alias stree='/Applications/SourceTree.app/Contents/Resources/stree'. If you use it, please report in the comments if and how it works and why you'd prefer it over the symbolic link.

For both methods, the path to stree in SourceTree.app must of course match the location where you installed SourceTree.app.

Now, stree is installed and can be accessed from any directory. The shortest way to open SourceTree when your shell's working directory is a repository's root directory is stree ..


For those of you on Windows, you can add a batch file named stree.bat to a folder in your PATH Environment Variable. (I have a C:\batch folder which is in my PATH where I store all my utility batch files.) Put the following in to your batch file:

@echo off
start "" "C:\Program Files (x86)\Atlassian\SourceTree\SourceTree.exe"

Now you can go to any Git or Mercurial repository and run this command which will open the repository in SourceTree.