Efficiently merge handle parallel feature branches in SFDX

There are numerous strategies for doing so (So, there is no 1 good answer), however, here are a few resources that can help answers some if not all those questions based on your needs:

GitFlow Examples

These examples are using the default configuration with GitVersion. Which is continuous deployment mode for develop and continuous delivery mode for all other branches.

Feature Branches:

enter image description here

GitHub Flow a nutshell:

  1. Update master to latest upstream code
  2. Create a feature branch git checkout -b myFeatureBranch
  3. Do the feature/work (Spawn Scratch Orgs to develop/test features)
  4. Push feature branch to origin
  5. Create pull request from origin/ -> upstream/master
  6. Review, fix raised comments, merge your PR or even better, get someone else to.

The main rule of GitHub Flow is that master should always be deployable. GitHub Flow allows and encourages continuous delivery.

For a more verbose description of each step, you can refer to Understanding the GitHub flow


I'm going to have to answer the questions out of order for them to make sense, and much of this is anecdotal at this point, but we've been doing this for a couple of years now, so I hope that this answer will be useful.

Is the recommended approach documented anywhere?

There are several competing theories on which way is the "best," and it's not related just to Salesforce, but any team that deals with git or another version control system. Salesforce only recommends that we use git, but doesn't prescribe a specific pattern, as far as I'm aware.

Should everybody pull and recreate and merge as soon as one story is done and merged?

Depending on the cadence of the team, this is more likely to be disruptive than helpful. There's a fairly simple way to handle this situation, which I'll outline below.

When do they recreate their scratch orgs?

Whenever they feel like it. You can do this one per story, once per feature, every time it expires, etc. Assuming all of the code is in your source of truth, it shouldn't matter.

When do they commit and push?

Commit periodically to have "backups" in case things go wrong, and push (preferably with a "squash") when it's ready to move on to the next branch.

When do they pull?

Immediately before branching or merging.

How would that look?

After a lot of painful experiences, we've come up with this process in general. Starting from the point where there's a new story to be implemented...

The repo should be organized with a master branch, a staging and/or test branch (for deployment to a master testing sandbox), and one branch per story or feature. Start by going to the "dev" branch, whatever that means for your org, pull to make sure you have the latest copy, then create a new branch to work in.

Developers then push the current state of affairs to a Scratch Org, and begin development using their preferred method. Periodically commit so you can fix mistakes if they happen or if your org expires, etc.

Once the story is complete, go back to the "dev" branch, pull again, switch back to the story branch, and merge the dev branch in to the story branch. This brings it up to date and will let you know of any merge conflicts.

Resolve any conflicts, commit again, and then merge/pull request back in to the dev branch. At this point, the dev branch should be good for testing and deployment. Finally, when deploying to production, a similar pull, merge, resolve conflicts (which ideally should not happen), and merge again cycle should happen.

Once everything is fully merged to production, you can delete the story branches to save space and optimize performance.


Our currently workflow:

  • git checkout -b feature/sales-api
  • git commit add .
  • git commit -am ""
  • git fetch origin
  • git rebase origin master

Once is done, rebase your branch to get the newest version of master, then:

  • sfdx package:version:create....

Actually we have more than one package in a project. Particularly, I don't like this approach, because if I have only one package by repository we could automate everything. Eg. after commit on develop/ build a version and install in the UAT. after commit on master/ build a new version/ update the release doc and install in production.

(Currently we have 35 packages)