How to use GIT on multi dev environment

I have previous experience using GIT in other development environment and I never had much troubles using it.

We where using SVN for salesforce, however we want to migrate to GIT for the uncountable number of advantages compared to SVN.

I could configure the remote and local repo without any problem and also I could commit and push the changes to my remote repo.

However, I can’t figure out how can we use GIT when more than one developer is doing changes on the repo. I always get conflict after refresh from server.

Sample where bought dev’s are working on the same repo/branch

Dev 1:

  1. Refresh from Server
  2. Change code
  3. Save to Salesforce
  4. Commit
  5. Push to remote

After Dev 1 pushing

Dev 2 (Steps A):

  1. Refresh from Server
  2. Change code
  3. Save to Salesforce
  4. Commit
  5. Push to remote (Error: out of date)
    1. If dev 2 try pull (or fetch + merge) then Conflict

Other steps we tried
Dev 2 (Steps B):

  1. Refresh from Server
  2. Pull (or fetch + merge) then Conflict

I was thinking in the possibility to use two branches: one for dev, just to be able to push commits to remote repo and the merged code will come always from Salesforce. But this practice will kill some of the GIT benefices as diff and blame.

I’ve tried searching on Google unsuccessfully.


There are a couple issues with how you’re using git, let me talk about each.

The problem

First, you’re treating your Salesforce server as the truth, instead of git. By doing a Refresh from Server each time before you’re starting to code, you are updating your working directory with whatever has changed in Salesforce. This will be reflected as a change pending commit on your local branch.

Second, you’re having developers share a Salesforce instance. Imagine that you’re each working on separate features on separate branches in git but on the same instance. If you do something like refreshing from server, all the stuff from your colleague’s branch is going to show up in your index, ready to be committed. Worse, what if you’re editing the same metadata files, you’re constantly overwriting each other.

The solution

Each developer needs his/her own Salesforce instance. Yes, keeping those instances up-to-date with a stable build (master branch) poses its own challenges but there are a ton of articles out there on continuous integration with Salesforce. This allows for feature development and accurate testing (since Salesforce controls the unit test environment) within your own branch and instance.

Also, you should be treating git as the truth. Right now, you’re trusting your instance but why wouldn’t you look to your stable build in git first. Step 1 in a VCS system should be a Pull, not a refresh from server. In this scenario, who cares what is on the Salesforce server, if it’s not in git it does not exist. And would you want it any other way, git is really designed to hold the history of your changes and Salesforce is not.

Source : Link , Question Author : Martin Borthiry , Answer Author : greenstork

Leave a Comment