Getting MavensMate, Github, & Salesforce to all play nicely

Matt/ March 8, 2017/ Salesforce

UPDATE July 2021:  I no longer use MavensMate and have not since shortly after writing this post.  I would hope the tool has improved in the 5 years since I wrote this post but if not, I would definitely recommend checking out IlluminatedCloud or Visual Studio Code as an alternative!

There’s been some confusion lately within my network about how to setup MavensMate, Github, and Salesforce so that they all hold hands together.

What does this look like?  I want a MavensMate project folder that doubles as a local Git project folder.

I’m documenting this process internally and since there seems to be very little documentation online about this, I’m hoping that sharing this publicly will help give back to the community.

1. Assumptions

I’m making several big assumptions here.

  • You’ve installed Sublime Text 3 & MavensMate & configured your preferences (specifically project folder);
  • You’ve installed MavensMate Desktop;
  • You’ve installed SourceTree & configured your preferences (specifically project folder);
  • You have a Github account (or an account on another Git option);
  • There’s an active repository you’re looking to connect to;
  • You’ve authenticated SourceTree to your Git repo; and
  • You’re running Windows, because they haven’t given me my Mac yet.

In your preferences for each, you should now have both MavensMate and Sourcetree project folders pointing to the same directory (if you don’t, why are you here?  This is the entire point!)

Further, a “how to use Git” tutorial is out of scope for this article. Got it?  Cool!  Let’s get started.

2. MavensMate

First we’ll focus on MavensMate.  Open MavensMate Desktop and select Create New Project. Select your URL type, and enter the URL.  Click the blue Connect button.

You’ll be asked to authenticate your project.  Authenticate.

In the Project Details tab, give your project a name (I’m calling mine “DBE”). In the Project Metadata tab, select all the Metadata types you wish to subscribe to.  When finished, click the blue Create Project button.

3. SourceTree

Close MavensMate Desktop.  In Windows Explorer, navigate to your project folder.  Look for the “DBE” folder you just created from your Salesforce environment.  Rename this folder to “zDBE” for easy access later.

Open SourceTree.  In the ribbon, click the Clone / New button.

In your browser, log into Github and navigate to your repo.  Click the Clone or download button, and copy the URL to your clipboard by clicking the highlighted button below:

Come back to SourceTree.  Paste that URL into the Source Path / URL field.  Destination Path and Name should fill in automatically.  NOTE: Make sure the Destination Path is the full path of the former name of the MavensMate project folder you just renamed.

Click the Clone button and wait for the import to finish.

4.  Holding Hands

Now we need to employ a little trick to get the different programs to work from the same folder.  First, close SourceTree.  Then go back to your Windows Explorer and make a backup of your DBE folder.  I called mine “gitDBE”.  This will serve as a backup so if I screw something up, I don’t have to start from the top of these instructions.

Navigate to zDBE folder.  Select everything* and select copy.  Navigate to your DBE folder and paste everything on top.  Overwrite everything.

Open up Sublime Text 3.  It probably pre-loaded a project, but we want to be absolutely sure this folder acts as a MavensMate project.  In the file menu, select File > New Window.  Close the window with the loaded project.

In the new (blank) window, from the menu select MavensMate > Project > Open Project…   Select the DBE project.  The project should open fine from the git project folder.  (If DBE is not in the list, you’ve done something wrong.  It’s a good thing you took that backup of the git project folder!)

Close Sublime Text 3.  Open Source Tree.  Your project should also load from the DBE project folder in Source Tree as well.

Congratulations!  You now have a folder that acts as both a Source tree project folder and as MavensMate project folder that is also connected to your Salesforce sandbox.

*NOTE:  You may find yourself in Source Tree with a bunch of uncommitted files.  This could be because because of different reasons:

  • Your SFDC environment is multi-tenanted with different apps, while your Git repo isn’t;
  • You’re subscribed to more metadata in MavensMate than was checked into git;
  • etc.

If this is the case, all you really need to copy over is your project folder’s .sublime-project and .sublime-workspace files, and the config file.  You may also have to configure your repository’s .gitignore file to ensure the following are ignored:

# Mavensmate/Sublimetext
/apex-scripts
/config
deploy
*.sublime-workspace
*.sublime-project
*.sublime-settings
.sublime-grunt.cache

And if other contributors to the project are using different OS systems, or different IDEs, you’ll have to add those relevant files to the .gitignore file as well.

Happy developing!

Share this Post

About Matt

Matt is a seasoned Salesforce Developer / Architect, with implementations of Sales Cloud, Service Cloud, CPQ, Experience Cloud, and numerous innovative applications built upon the Force.com platform. He started coding in grade 8 and has won awards ranging from international scholarships to internal corporate leadership awards. He is 37x Certified on the platform, including Platform Developer II, B2B Solution Architect and B2C Solution Architect.

3 Comments

  1. Still helping folks over a year later!

    I wrestled with this earlier this week and ended up with like 4 folders and pretty much just manhandled the files back up into bitbucket. Gonna try this route today and see if I can end up with a little less chaos 🙂

    Thanks!

  2. Hello,

    I find this article is very useful.
    However, I have two question.
    1- I get this error message while cloning the repo and pointing the destination path the Mavensmate’s project folder. Please not that my remote repo have already metadata inthere. so the remote repo should be empty to use your method ?
    2- If the repo will be used by different people, are the same steps still applied ?

    Thanks for your reply

    Regards

Comments are closed.