Github: The Source Code Management Solution For Salesforce
Source code management for Salesforce is easy to setup and manage using Github’s cloud based Git repository service. Git is a command line based source code versioning tool with full history tracking which has been around for many years and which allows collaboration for developers via central project repositories. Github allows central repositories to be setup quickly and easily in the cloud and extends command line Git with a very intuitive and easy to use Web UI as well as plugins to IDE’s.
Developers can push to and clone or pull code from Github repositories as well as merge code easily via Github’s “Pull Request” functionality. Pull Requests provide a basis for merging and for notifying all developers on the project of pending merge requests, highlighting code changes, merge conflicts, and allowing code review feedback via inline comments through the Web UI.
Github Web UI: Pull Request with no Merge conflicts (Screenshot below)
Salesforce “Metadata” provides the key to source code management. Developers can retrieve all or part of their Salesforce Organisation’s Metadata content pending development requirements and push this Metadata to Github for source code versioning and collaboration.
How to Setup and Use Salesforce Version Control with Github
- If not already registered setup a Github account (http://www.github.com) and create a private project repository.
- Install Git on your local device and clone the origin Github repository.
- Using a Package.XML file for content definition retrieve from SFDC all required Metadata files for versioning. This can be achieved via an IDE for an existing Force.com project or via the Force.com Migration Tool https://developer.salesforce.com/page/Force.com_Migration_Tool
- Copy the Metadata content to your local cloned Git repository folder and configure the folder as your IDE’s Force.com project workspace. Using command line Git (or Git/Github plugin if installed to your IDE) commit the content and push to Github origin.
Note EGit is a useful plugin to allow Git/Github integration with Eclipse and the Force.com IDE. It can be installed via the Eclipse Marketplace, Software and Workspace Centre. Sublime Text has many Git/Github plugins such as Git, SublimeGit, SideBarGit, and Sublime Github which are available via the Sublime Text “Package Control” plugin.
- Your Github project repository is now ready for purpose.
Github Web UI: Project Repository containing SFDC Metadata files (Screenshot below)
- Developers added as Team Members for collaboration can now clone the Github repository to their local devices, set the repository folder as their SFDC project workspace folder and start branching from the Trunk (Master) branch to create branches for each new development task.
- Developers can commit and push each branch to Github while developing and when satisfied that tasks are complete create Pull Requests for branch merging.
- Once Pull Requests have been merged deployments can be made to SFDC sandbox or production environments as required from the version controlled code.
Github Web UI: Repository Branch/Commit History (Screenshot below)
- Deployments can be performed directly from the remote Github repository using repository hooks in continuous integration tools such as Jenkins (http://jenkins-ci.org/) or manually from up-to-date local cloned Git repository workspace folders via the Force.com Migration Tool or Developer’s IDE.
Source code control for Salesforce could not be easier therefore or quicker to setup than when using Github and Git.