GitHub and Salesforce

How to track Salesforce Metadata in GitHub with Blue Canvas.

Blue Canvas automatically tracks changes to your Salesforce metadata (including declarative changes) and commits it into Git. Because we operate on open standards, it is easy to connect Blue Canvas and GitHub so that you can keep track of your Salesforce metadata in GitHub. You can see a Salesforce and GitHub example repo here.

Prerequisites

  1. Connect your Salesforce Orgs to Blue Canvas using the Quickstart Guide
  2. Install Git locally. You may already have it. 💡 This is not a Blue Canvas requirement, it really is needed only if you intend to track changes externally from Blue Canvas too.

Clone Your Git Repo Locally

Blue Canvas creates a Git repo for you and automatically keeps it in sync with your Salesforce orgs. Once we have connect our orgs, we can use the command line to clone the Blue Canvas repo into our local laptop.

Visit the Branches tab in Blue Canvas and scroll down to the Blue Canvas Git - Command Line Instructions. Here you will see your Git repo URL:

git clone -o salesforce -b master https://git.bluecanvas.io/t6a289876a56-df47-4226-b497-c2f6bc2a121e/r1a019c88-220e-40d5-81e6-2b5476dc6681.git my-repo

Run the git clone command on the command line. To name the directory that this Git repo lives in on your local file system, add a directory name of your choosing to the end of the command like so:
This will clone your Blue Canvas repo into a directory called my-repo.

Now you have Blue Canvas set up as a remote called salesforce on your local machine. You can pull changes from this remote into your local environment at any time. You can test this by making a change through the Salesforce developer console. Once Blue Canvas picks this up you can go to the command line and issue the following command:

git pull salesforce <branch-name>

You should now see whatever changes you made to the metadata show up in your local repo.

Adding a GitHub Remote

Next we just have to add GitHub as a remote. This is simple.

First, create a GitHub repo. You will see instructions for “push an existing repository from the command line”:

Go to the command line and add the remote:

git remote add github https://github.com/GITHUB_USERNAME/REPO-NAME.git
git push -u github <branch-name>

Note that you can name the remote anything you like. We have chosen github for clarity, but GitHub uses the convention of origin. It’s really up to you. The remote name is important because it allows you to determine which repo you are pushing and pulling from. This will soon become apparent.

To test that this work, go to the command line and type git remote. You should see two: github and salesforce.

Syncing Remotes

To sync remotes, you simply pull from the Blue Canvas repo (salesforce remote) and push to GitHub (github remote) like so:

git pull salesforce 
git push github <branch-name>

That’s it! Now you should see all of your Salesforce information in GitHub like so:

Anytime you want to bring your GitHub into sync with what’s happening in Blue Canvas do a git pull from Blue Canvas and then git push to GitHub.

Automating This With Post-Receive Hooks

In the future, you’ll be able to automate this process with post receive hooks. To learn more check out the Git documentation. And we’ll update this documentation when it becomes available. Please see the GitHub documentation about GitHub mirrors for more information.