Source Tree is not using correct system Git
Asked by Danail Nachev:

I've installed Source Tree and set it up to use system Git. However, it shows that the Git is version 1.7.4.1, but if execute:

```
git --version
```

I get:

```
git version 1.7.7.2
```

Perhaps, this is because I'm using Macports' Git and not the git distributed with Mac OS.


Answers:
author: stevestreeting
body: Yeah, this happens in 1.2 because SourceTree picks the first git it finds (and can't know what your PATH is). In 1.3, which is in beta now and will be released soon, when you click 'Use System Git' SourceTree prompts you with a browse dialog so you can point it elsewhere from the one SourceTree detects if you want.

comments: author: Barrett Heyneman
body: I realize this is a fairly old thread, but I can't find a more recent one and this doesn't seem to work (Sourcetree 1.6.2.2).

I'm running Mac OSX 10.8.4, which came preloaded with Git, 1.7.12.4 (Apple Git-37), located in /usr/bin. I wanted to take advantage of some new features in Git 1.8.2+, so I installed the latest version into /usr/local/git/bin and had Sourcetree use the system git at that location. I also updated \~/.MacOSX/environment.plist to prepend that to the default path (which as I understand it will allow non-terminal applications to search there first for any executables).

However, after all this some of my custom actions were not working because the git they used didn't have these new features. To test I created a simple custom action that only ran "git --version": it still returned the 1.7.12.4 Apple-supplied version. When I renamed the git exectuable in /usr/bin the action failed completely because it couldn't find a git executable.

It \*seems\* to me that Sourcetree is explicitly executing custom-action git related commands using executables found in /usr/bin, and not actually relying on the PATH to find the first one available. Unless I hear otherwise, I will file a bug, as this doesn't seem like it's the intended behavior when you explicitly choose the system git executable.

For now, I've found the workaround to be manually placing a symlink in /usr/bin pointing to my /usr/local/git/bin/git executable


author: stevestreeting
body: We actually can't control everything in your custom actions, if you're using a script which is using bash then it's likely that it's overriding the PATH it has inherited from SourceTree (e.g. in .profile). All SourceTree can do is call it within its own environment, if it changes the PATH after that, that's out of our control.


author: Barrett Heyneman
body: That makes sense. However, I tried my best to make sure that the location of the new git executable would be available to all Apps. I am semi-new to MacOSX, so I may have gotten something wrong.

The new git is in /usr/local/git/bin. I have prepended that to my PATH in \~/.bash_profile (via sourcing \~/.bashrc, which actually does the exporting), which I understand only affects my bash shells, not Apps. I also added it to the default PATH in \~/.MacOSX/environment.plist. To verify, I get

```
Barrett$ echo $PATH&gt;&gt;&gt;/usr/local/git/bin:/Applications/microchip/xc32/v1.20/bin:/Applications/microchip/xc16/v1.11/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/texbinBarrett$ defaults read ~/.MacOSX/environment&gt;&gt;&gt;{&gt;&gt;&gt;    PATH = "/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/sur/X11/bin:/opt/local/bin";&gt;&gt;&gt;}
```

which looks like it's setup correctly. However, when I create a Custom Action which calls "printenv" I get

```
PATH=/usr/bin:/bin:/usr/sbin:/sbin
```

Is there some other place I need to add the path in order for SourceTree to include it in the shell it creates for custom actions? You mentioned .profile in particular, which I didn't have. But, after adding it with the same PATH exports (via sourcing my .bashrc, if that makes a difference), I still see the same PATH from the SourceTree custom action shell.

Thanks,

-Barrett

PS: Is there a better place for this discussion?


author: stevestreeting
body: Recent versions of OS X no longer respect the contents of environment.plist, sadly - you'll need to use launchd.conf instead: <http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x/4567308#4567308>


author: Barrett Heyneman
body: Well, that would explain it...

Thanks a bunch for the help.

-Barrett


author: Warner Nanninga
body: @Colin Goudie

In my case not. Sourcertree says System Git version 1.7.12.2 (pointed it to the xCode.app (show package content -\> Content -\> Developer -\> usr -\> libexec -\> git-core -\>git)).

Terminal says git version 1.7.10.2 (Apple Git-33) (git --version).

Dont know why or how.

comments: author: stevestreeting
body: Running 'which git' on the command line will probably show your terminal is using an older version from somewhere else.


author: Warner Nanninga
body: Hi Steve,Should i echo 'export PATH=/usr/local/git/bin:$PATH' \>\> \~/.profile?Also i have got a folder named git in the Home directory. Is this a other version of git than the Apple xCode one?Thanks for your time and effort.


author: stevestreeting
body: What I would personally do is point your system git in SourceTree to wherever 'which git' points on the command line, which is usually '/usr/local/git/bin/git' (this should be the default anyway).

As for editing your profile, yes if your PATH doesn't already include /usr/local/git/bin then that would do it. That's usually configured for you though when you get a command-line version of git (either from [git-scm.com](http://git-scm.com) or by installing the command line tools from inside Xcode from Preferences \> Downloads).


author: Warner Nanninga
body: Hi Steve,Thanks for your help and answer. I will point Source Tree to the Usr/local/...Have a nice day, in my part of the world the sun is shyning at the moment. I hope it will for you to.


author: Colin Goudie
body: What happens when you run **which git** from the commandline. Is the output the same as the git you set up in sourcetree?