Any simple ways of keeping a subset of your apex code in sync with a git repo?


I'm a consultant, and over time we've built out a number of helper classes that we use across our engagements. It'd be really awesome if there were a simple way to hook our org up to a git repo with our helper classes and easily pull down the latest updates from the master repo. My dream would be a simple page that I can plug in a git repo, lists out all of my installed repos, and let's me easily pull updates if there are any. Has anyone wanted to do this and figured out a simple route to make it happen?


I'm very aware of managed packages, which are awesome for a lot of reasons, but problematic for just as many. For the purposes of those questions please consider managed packages out of bounds.

  • How about an unmanaged package? You can just create them from any dev org and then if you have the install link, it is super easy to add to your org. To update, just get the latest install link and it should write over the changes. Sep 10, 2013 at 2:42
  • If only that's how they worked :(, you install them, make a minor change, then try install again and get a big "component blah, blah, blah, already exists in your org". The only thing I dislike more than managed packages are unmanaged packages. Sep 10, 2013 at 2:48
  • 1
    Really? Oh well, that's why I posted as a comment! Didn't have the time to research. I thought for sure you could install again. Sep 10, 2013 at 3:01
  • @Ralph There is a way to manage Apex code from git and can track change in each line, but you have to install package each time you make some changes in package.
    – Ashwani
    Sep 10, 2013 at 5:48
  • @responsive would i still have to use a managed package? Sep 10, 2013 at 6:28

2 Answers 2


I'm also a consultant. We don't see a need to mess with the Ant tool or any of that nonsense. We utilize MavensMate and Sublime Text 3 along with the sourceTree or the git client of your choice.

MavensMate handles the local <--> sfdc connection and git takes care of the rest. If you're not set on a fancy gui for git you can even do everything inside SublimeText 3.

I highly recommend it!

  • I also do much the same with the Force.com Eclipse IDE and the GitHub client. I create a basic .project file in a folder in my Github working directory, then use Eclipse to Import Project, any Metadata (apex code, triggers, objects etc) the Force.com IDE manages automatically appear in my GitHub working directory and I can commit them via the GitHub client. Sep 11, 2013 at 8:42
  • 1
    but but but ... Andrew, friends don't let friends use eclipse ... ;)
    – Kevin P
    Sep 11, 2013 at 12:47
  • And how would you do this if it's project's shared across multiple projects? Sep 11, 2013 at 22:22
  • @Ralph, How do you mean?
    – Kevin P
    Sep 12, 2013 at 11:59
  • Each client has their own repo. We also have code that is used across all the clients, in a different repo. Trying to figure out how to simplify the process of getting changes to that code out to all clients (without having to deal with managed packages) Sep 12, 2013 at 15:29

You could accomplish this with ant and the Metadata Toolkit.

  1. Install Apache Ant.
  2. Install Metadata Toolkit into Ant.
  3. Install git.
  4. Configure git.
  5. Create build.properties, build.xml, and package.xml.
  6. Pull initial set of classes, components, etc using sf:retrieve.
  7. Commit initial repo for git.

At this point, you've got a working baseline. Ant can manage all of your code needs, such as:

ant sfdcToCommit # Retrieve from SFDC, and stage or commit git
ant revertSfdc   # Revert to last git revision and save back to SFDC

The limits of this model is basically your imagination.

I haven't personally implemented this (never crossed my mind until just recently), but it's safe to say we have all the necessary tools to effectively do this.

  • Excellent point. Let's say I'm an admin and I don't like the command line, what about a way to do this directly in Salesforce? Sep 11, 2013 at 22:22
  • I'm not aware of one, but... I'll put it on my todo list. It sounds like fun.
    – sfdcfox
    Sep 12, 2013 at 0:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .