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.
Another Windows solution for those who use Git on the Bash command line (msys).
Add two functions to your Bash .profile:
# Courtesy: http://stackoverflow.com/questions/12015348/msys-path-conversion-or-cygpath-for-msys
function towinpath {
{ cd $1 && pwd -W; } | sed 's|/|\\|g'
}
function stree {
if [ -z $1 ]; then
stree_path=$(towinpath pwd)
else
stree_path=$(towinpath $1)
fi
echo "Starting SourceTree in $stree_path"
/c/Program\ Files\ \(x86\)/Atlassian/SourceTree/SourceTree.exe -f $stree_path status
}
Reload your shell.
Now you can use:
$ towinpath /c/Temp
And it will echo c:\Temp.
Or you can open SourceTree:
$ stree .
And it will open this repository in SourceTree defaulting to the Status panel.
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 ..
If you have cygwin installed, you can use this as your stree.bat. This batch file uses cygpath to resolve . to its absolute path, so you can do stree .
@echo off
FOR /F "tokens=* USEBACKQ" %%F IN (`cygpath -w -a %1`) DO (
SET STREE_OPEN_PATH=%%F
)
%USERPROFILE%\AppData\Local\SourceTree\SourceTree.exe -f "%STREE_OPEN_PATH%"
Adapting from multiple answers here for Windows, these scripts will allow you to get SourceTree running from command line (tested on SourceTree 3.0.1.7 / Windows 10).
Scripts in a PATH directory
I've placed both these scripts in a folder that is in my system PATH. You won't have to modify your bash profile for this script.
Git Bash for Windows
Create a file named stree (touch stree) in your PATH linked directory and run chmod u+x stree on this file.
#!/bin/sh
function towinpath {
{ cd $1 && pwd -W; } | sed 's|/|\\|g'
}
if [ -z $1 ]; then
stree_path=$(towinpath pwd)
else
stree_path=$(towinpath $1)
fi
$LOCALAPPDATA/SourceTree/SourceTree.exe -f $stree_path log &
You can replace "log" in the last line with "status" if you prefer the changes/working directory view of your repository in SourceTree.
Command Prompt or Powershell
Create a file named stree.cmd in your PATH linked directory.
@echo off
start "" "%LOCALAPPDATA%\SourceTree\SourceTree.exe"
Note that this won't actually open up the directory as a repository.
Please feel free to improve the scripts, especially the one for Command Prompt.
N.B: the path C:\Users\userexample\AppData\Local\SourceTree\SourceTree.exe can be changed to whatever SourceTree is installed,
for Exp: if SourceTree is installed with admin privileges this path will be C:\Program Files (x86)\Atlassian\SourceTree\SourceTree.exe and the command will become