Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you open SourceTree from the command line?

Is there a quick and easy way to open a git repository in SourceTree from the command line?

I do a lot of git work from Terminal, but sometimes there's no replacement for a good history view/diff. Would love to be able to open without using bookmarks.

like image 774
loeschg Avatar asked Oct 29 '13 15:10

loeschg


People also ask

How do I open Sourcetree?

Or you can open SourceTree: $ stree . And it will open this repository in SourceTree defaulting to the Status panel.

How do I access Git from command line?

Edit the System Variable called PATH. Close the CMD prompt window if it is open already. CMD needs to restart to get the updated Path variable. Try typing git in the command line, you should see a list of the git commands scroll down the screen.


2 Answers

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' 
like image 91
loeschg Avatar answered Sep 28 '22 19:09

loeschg


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

like image 45
Erik Avatar answered Sep 28 '22 20:09

Erik