SourceTree- VBA Macros via xltrail
Asked by jkeeney:

I have been developing some VBA Macros in Excel and I would like to use revision control to help manage the development.

I have discovered <https://www.xltrail.com/client> which is an open source Git command line extension: git-diff and git-merge.

It seems to work great from the git command line. However, I am used to using SourceTree. Anyone know how I can merge these two together?

Under git I tried system git instead of embedded. I also tried playing around with the external diff/merge options. I couldn't seem to get it right.

xltrail added the following to my .git/config file if this helps.

\[diff "xltrail"\]  
command = git-xltrail-diff.exe  
\[merge "xltrail"\]  
name = xltrail merge driver for Excel workbooks  
driver = git-xltrail-merge.exe %P %O %A %B

I am a beginner with Git and SourceTree. Any help would be greatly appreciated.


Answers:
author: fzumstein
body: Hi [@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547) I am one of the maintainers of git-xltrail. I see that it now works with SourceTree 3.0.12. However, I can only see it working in the case of uncommitted changes, not for already committed changes. Is there a simple reason for why that is? We're happy to do changes on our side as per your suggestion but I was wondering if the current behaviour was expected. Thanks for a quick feedback!

comments: author: fzumstein
body: I wrote a short blog post about how to use SourceTree with git-xltrail: <https://dev.to/fzumstein/how-to-diff-excel-vba-code-in-sourcetree-git-client-36k>


author: fzumstein
body: Just to minimize confusion: We have renamed git-xltrail into Git XL and hence all commands are now "git xl" instead of "git xltrail". Everything else stays the same, but during upgrading it might be best to completely uninstall git-xltrail before you upgrade to git-xl.


author: Tony Pinter
body: [@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547) [@fzumstein](/t5/user/viewprofilepage/user-id/746778) What follows isn't technically an answer, but I figured it would make sense to keep a related beginner xltrail/sourcetree question in the same (and only similar) thread.

Along similar lines to OP I'm a relative beginner with Git, xltrail, and SourceTree, and I've been playing around with using these tools to manage some xlsm files.

Everything seemed to be working swimmingly, but I ran into some trouble when I edited a VBA module in one of my xlsm files and then observed it in Sourcetree.

![2.png](https://community.atlassian.com/t5/image/serverpage/image-id/62463iB9615D6115296CEB/image-size/large?v=v2&px=999 "2.png")When I try to stage or discard lines/hunk, I get the following error:

![3.png](https://community.atlassian.com/t5/image/serverpage/image-id/62464i6EEF06471BCD6999/image-size/large?v=v2&px=999 "3.png")

The content of that file is:

**diff --git a/diff_results.xlsm b/diff_results.xlsm**

**--- a/diff_results.xlsm**

**+++ b/diff_results.xlsm**

**@@ -11,8 +11,8 @@**

**' Return code?**

**Call RunPowerShell(cmd, "CompareResults")**

**\[31m-' dummy comment added**

**\[32m+' dummy comment revised after being added**

**End Sub**

**Sub CallCompareResults()**

I verified that I could discard hunk with a change to a simple text file, so I think my basic sourcetree and repo setup is right. Perhaps xltrail doesn't support patching like this? Or might something else be the problem?


author: Mike Corsaro
body: Just to provide an update on this one -- it's going to take a bit longer than expected due to xltrail not producing a standard git diff:

* It ignores most diff command switches such as color formatting and mnemonicprefix
* It outputs as if there are multiple files (which is OK), but doesn't add an additional diff header

Thanks for your patience!

comments: author: jkeeney
body: Thanks for the update!

Not trying to hold you to anything. However, do you have an idea if this might be on the order of weeks, months, etc.?


author: Mike Corsaro
body: *Probably*in the 2.7 release, which will be coming in the next few weeks.


author: Daniel Shunfenthal
body: A couple weeks is pretty good, thanks!

Should those issues be brought up to them? Or do you think you can handle it on your end?

As an aside, I would've thought color formatting is handled by SourceTree?


author: Daniel Shunfenthal
body: [@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547)Is there any update to this out of curiosity? Is it still slated for the next release, and if so do you know when that is coming out?


author: Kade333
body: [@Mike Corsaro](https://community.atlassian.com/t5/user/viewprofilepage/user-id/842547)

I have installed [xltrial](https://www.xltrail.com/client) and it works as intended in the command window as intended.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/49738i8B4520605D31A971/image-size/large?v=v2&px=999 "image.png")

Unfortunately, it is not showing up in the GUI window as shown [here](https://dev.to/fzumstein/how-to-diff-excel-vba-code-in-sourcetree-git-client-36k#sourcetree-with-gitxltrail-activated).

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/49737iE99174F978C2EA6A/image-size/large?v=v2&px=999 "image.png")

I am running version SourceTree version 3.1.2.

Is there something else I am supposed to to in order to get this to work, or are you still working on the patch?


author: Mike Corsaro
body: Seems to work fine for me?

![diff.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/49749i35F4586C24D0F567/image-dimensions/466x150?v=v2 "diff.PNG")

Are you sure you have everything configured?

Open the Process Log (Tools \> Process Viewer...), click on the file to generate the diff, and then check the process output. It should look something like this:

```
[1mdiff --xltrail a/Book1.xlsb b/Book1.xlsb
 [1m--- a/Book1.xlsb/VBA/Module/Module1
 [1m+++ b/Book1.xlsb/VBA/Module/Module1
 [36m@@ -2,3 +2,7 @@
'test1
Sub test()
Debug.Print "hello1"
 [32m+End Sub
 [32m+
 [32m+
 [32m+gsdgdsg
```


author: fzumstein
body: Hey [@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547) , I think what might happen is that [@Kade333](/t5/user/viewprofilepage/user-id/1412227) is looking at two historical commits, while you're looking at pending commits (where it works). Is there anything we'll need to change (I am one of the maintainers) to make it work for historic commits, too?


author: Mike Corsaro
body: [@fzumstein](/t5/user/viewprofilepage/user-id/746778)nothing you need to do on your side -- looks like 'diff-tree' doesn't have the default diff settings of '--ext-diff' like 'log' and 'diff' does for some reason. I'll add it to our backlog and hopefully it will be included in the next release.


author: fzumstein
body: awesome, thanks!


author: sai velagapudi
body: Hey [@fzumstein](/t5/user/viewprofilepage/user-id/746778) , your blog is great and very helpful. I recently started developing VBA and started to use Sourcetree along with my other Java projects. I can't wait to be able to compare historical diff's.

[@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547) , Any ETA on the timeline for this?


author: Mike Corsaro
body: It's been fixed in 3.1.3 which is at 25% in our progressive rollout. [You can also manually download it here.](https://product-downloads.atlassian.com/software/sourcetree/windows/ga/SourceTreeSetup-3.1.3.exe)


author: sai velagapudi
body: Cool.Thanks


author: Andrew Dorfman
body: [@Mike Corsaro](/t5/user/viewprofilepage/user-id/842547) , thanks, I was struggling to make SourceTree (v3.2.6) work with that but couldn't and after I posted a question here it started to work)

Actually I believe there is still a problem in some cases: there is one command (from the logs) that is not calling Git XL and the other command is calling it and producing a proper diff output.

The command #1 that works - as it is in my SourceTree log file:  
git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks diff-tree --oneline --unified=3 --root -w -M -C --ext-diff 6b4...3b7 -- \\"Test_GitXL/Variation.xlsm\\"

This command #2 doesn't work with Git XL:   
git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks diff --unified=3 -M --no-color -- \\"Test_GitXL/Orica Contract Variation.xlsm\\"

"Output" of second command is : "diff --git a/Test_GitXL/Variation.xlsm b/Test_GitXL/Variation.xlsm\\nindex 0a51..1fec 100644\\nBinary files a/Test_GitXL/Variation.xlsm and b/Test_GitXL/Variation.xlsm differ\\n"  

Output from command #1 is meaningfull diff results...

Possibly I'm missing something in my Git knowledge, can't see why #1 works while #2 doesn't.... difference is that #1 has diff-tree and ext-diff... but what does that mean?

Andrew D


author: Mike Corsaro
body: Hello! Sourcetree doesn't currently support doing this as we explicitly disallow external diff drivers for specific file types. However, I don't see why we couldn't support this as it's a pretty small change for us to make.

comments: author: jkeeney
body: For what it is worth, that would be a huge help to me.

SourceTree is a critical part of my development for all of the other languages I code in. Being able to use SourceTree for my VBA development would be a huge win.

I still use it, but not being able to use diff and merge limits its usefulness.

Thanks for considering this!


author: Daniel Shunfenthal
body: Hey, just wanted to throw my support in for this as well! It would be so nice to be able to use xltrail + Sourcetree's diff viewer.