Steps on how to adopt Git-Based Salesforce Development

Salesforce developers have long faced challenges with version control and collaboration due to the platform's unique nature. This makes it problematic to integrate with standard version control systems like Git. However, there is good news for Salesforce enthusiasts.

  • Published 29 Apr 2024
  • 10 mins read
Steps on how to adopt Git-Based Salesforce Development
Table of contents
Article Highlights
  • Git-based development enables Salesforce teams to use version control effectively, managing metadata and source code changes collaboratively and efficiently.
  • Adopting a Git-based approach helps overcome the inherent limitations of Salesforce’s lack of built-in version control, by synchronizing metadata with Git repositories using Salesforce DX and its CLI.
  • The use of Git allows for seamless collaboration among developers, supporting multiple workflows and enabling rollbacks to previous versions, which enhances overall project management and quality assurance.
0:00
/

It is no secret that Salesforce lacks built-in version control for metadata. Git has become a de facto standard for developers worldwide across most software development technologies due to its:

  • Robustness
  • Speed
  • Support for various workflows.
This makes it an ideal candidate for managing source code and metadata of any kind, including Salesforce metadata.

Using “shadow version control” – occasionally pulling all metadata of an org and storing it in Git for backup purposes – has been a common practice for many Salesforce teams for a long time.

🚪
However, the launch of Salesforce DX and its CLI opened the doors for true Git-based Salesforce development. SFDX enables developers to track changes and synchronize metadata with Git repositories.

Together, these tools bridge the gap between Salesforce and Git, simplifying the management and collaboration on Salesforce projects.

Understanding the benefits of using Git with Salesforce development (and the steps to implement it) is crucial.

To understand Git, you need to first comprehend the challenges of version control

Effective version control is essential to unlocking the full benefits of a robust DevOps process for Salesforce. It paves the way for automation, streamlining development and release cycles. This enables Salesforce teams to build, test, and deploy code and configurations more efficiently.

However, teams must overcome common challenges to successfully implement source-driven and automated workflows.

Version control's adaptability, which is its strength, can also cause complications that make it challenging to adopt.

When teams begin using version control, they encounter multiple obstacles. Primarily, two initial hurdles must be overcome:

  • Identifying the right approach: Teams often have difficulty determining the appropriate Git branching approach
  • Training and enlisting the team's support: Non-technical members need to be equipped to contribute to a git-based development lifecycle.

Now that you know about the challenges behind version control, let’s look at how Git-based development comes in and saves the day.

What is Git-Based Development

As mentioned, Git-based development means no longer considering a Salesforce org the “source of truth” of your configuration, but rather your version control system.

Git-based development allows developers to:

  • Work collaboratively on the same codebase
  • Track changes and versions
  • Merge and manage code changes
  • Roll back to previous versions when necessary.
🤖
With Git-based development, developers can simultaneously work on different code branches, test new features and fixes, and smoothly integrate and combine codebase changes.

This approach has become a widely accepted best practice for software development because it can improve team engagement, increase efficiency, and refine the development process.

Git-based development is used in various software development environments, including web development, mobile app development, and enterprise software development.

Salesforce has introduced the DevOps Center, which promotes Git-based development on the Salesforce platform for both low-code and pro-code development. However, as the tool is still rather new, it has left many vital gaps for the ecosystem of Salesforce DevOps solutions to close.

Utilizing Git-based development offers several benefits, such as:

  • Maintaining a consistent record of all metadata states
  • Identifying and managing conflicts early on
  • Executing control and quality assurance on a contributor’s work.
2️⃣
When it comes to Git-based development for Salesforce, there are two approaches – active and passive.
  • Active Git-based development involves utilizing Git as the primary source of code changes and following standard version control workflows. Developers create, work, and edit on their branches and collaborate using pull requests
  • The approach of Git-based development in passive mode views Git as a means of backing up and preserving historical data. Developers primarily make changes directly in Salesforce orgs and intermittently update the Git repository to sync their modifications.

Why you should utilize Git

Streamlined release management

With Git, release management becomes more efficient as developers can easily control code alterations and explore new features in the main codebase.

Low learning curve

Git-based development is widely used and has extensive documentation, making it easy for developers to learn and get started. There are various resources and courses available to help you grasp Git faster. A good place to start would be on Trailhead. You can learn at your own pace while gaining invaluable knowledge and insights.

Increased productivity

Git-based development can help developers become more productive by providing a collaborative and efficient development process, resulting in faster development cycles and better-quality code.

Better branch management

This type of development allows teams to create and manage multiple code branches, enabling them to work on different features or fixes simultaneously and easily merge the changes into the main codebase.

Improved deployment workflow

Git enables developers to create self-operating deployment workflows, reducing the risk of deployment errors and improving the overall deployment process.

Flexible development environment

Git-based development allows developers to work on different development environments, including local, staging, and production environments, without interfering with each other's work.

It also gives managers options for different types of code. Git can be used for various development projects, from small-scale projects to large-scale enterprise applications.

Community support

Git has a strong community of developers who contribute to its development and provide support to others.

Better bug tracking

Git-based development provides better tracking of bugs and issues by enabling developers to associate specific functions with specific bugs or problems and providing an audit trail of changes made to address those issues.

Seamless integration

Git integrates easily with other development tools, such as continuous integration and deployment tools, making it easier to self-act the development process.

Strong security

To protect sensitive code and data, Git-based development offers robust security features, such as user authentication, access control, and encryption.

Efficient documentation

Git offers an efficient way to document code changes, enabling developers to create clear and concise documentation of their code, This makes it easier to understand and maintain the codebase.

How to adopt Git-Based Development

For those interested in implementing Git-based Salesforce development, straightforward steps can be followed.

♻️
It's important to bear in mind that these steps are tailored towards individuals in release manager positions or those responsible for managing the application lifecycle.

1. Set up your environment

Install a set of free tools. These tools can be Salesforce DX, Visual Studio Code with the Salesforce extension pack, and Git.

2. Utilize a Salesforce DX project

  • Open Visual Studio Code and the Command Palette using the shortcut ‘Command+Shift+P.’ You can select “View” and then “Command Palette”
  • Click on “Command Salesforce DX” and then “Create project”
  • Be sure to choose the “Standard” project type.

3. Collect your current Metadata

To get started, use Salesforce DX to establish a connection between your computer and your existing Salesforce org. This can be achieved by accessing the Command Palette, choosing "Command Salesforce DX," and selecting "Authorize an Org."

In the past, retrieving metadata from your org was a difficult task, but this functionality is now built-in with Salesforce DX.

The first command generates a "package.xml" file with a list of metadata from your org. The second command then uses this file to fetch the specified metadata.

sfdx force source manifest create -t package --fromorg <orgalias>
sfdx force source retrieve -x package.xml -u <orgalias>

4. Develop a Git Repository

To get started, visit a Git host such as:

Firstly, establish a secluded repository and acquire its URL upon completion.

In case your organization's security policies prohibit the use of cloud-based repository hosting, alternative options provide enterprise-grade security features.

☝️
Next, set up a local Git repository, establish a connection with the remote repository, and proceed to upload your project to the remote repository.
git init
git add .
git commit -m "initial metadata fetched from org"
git remote add origin <url of your repo>
git push -u origin main

5. Utilize source-tracked orgs

There are three categories of organizations that endorse source tracking:

  • Scratch orgs
  • Developer sandboxes
  • Developer Pro sandboxes.

Although both sandboxes and scratch orgs are viable alternatives, some see scratch org-based development as the preferred method.

💡
For a comprehensive examination of the benefits and drawbacks of utilizing scratch org-based development, you may consult this illuminating post by Diéffrei Quadros on Medium.

Typically, scratch orgs are ideal if your project allows for reverting to sandboxes.

Developers who contribute to your source code will require specific instructions to fetch their work from their source-tracked organizations and submit changes made in their local environment, usually using code from Apex or Lightning Web Components.
sfdx force source push 
sfdx force source pull

Once a unit of work is finished, you can use the built-in capabilities, Visual Studio Code, or command line to commit and push it to Git.

🌍
The procedures discussed so far apply to Git-based development, whether inside or outside the Salesforce ecosystem.

While they provide a fundamental understanding, Git involves additional complexities, including branching strategies and other commands, that are worth exploring.

For some members of the Salesforce team, such as admins and low-code or no-code developers, this could be overwhelming. It is the primary obstacle encountered by Salesforce teams when transitioning to a Git-based application lifecycle.

Fortunately, third-party tools like Hutte can simplify the process of shifting to Git, enabling both coders and non-coders to collaborate in a development workflow within Salesforce.

6. Make your changes

To finalize the workflow, you must generate a pull request, which can be done through the GitHub user interface or command line. Pull requests are a crucial step in Git-based development, allowing you to refine your work before submission.

💬
When creating a pull request, it is important to provide meaningful comments for others, ideally referencing your issue-tracking system.

Most Git hosting services generate a unique URL when you push your branch, which can be utilized to create a pull request through a web browser. Alternatively, you can use the command line to submit your pull request.

Here is an illustration of code to generate a pull request using GitHub CLI:

gh pr create --title "my title"

Depending on your team's structure, some contributors may choose to finalize their Git development by submitting a pull request.

7. Merge your changes

Once a pull request has been submitted, the release manager typically reviews and merges it, followed by promotion to higher environments, such as user acceptance testing or production. This can be accomplished either manually or with the assistance of automation.

🔐
There are various options available to deliver your work, such as deploying metadata, executing changes from a single unit of work, or utilizing managed or unlocked Salesforce second-generation packages (2GP).

Despite being an efficient approach to promoting changes, 2GP is often overlooked, and there are Salesforce DX plugins available to facilitate this process.

Here is a sample of how to deploy the metadata from the most recent merged pull request in Git to a Salesforce sandbox or production org:

sfdx sgd source delta --from "HEAD~1" --to "HEAD" --output "." --ignore .forceignore
sfdx force source deploy --manifest package/package.xml --postdestructivechanges destructiveChanges/destructiveChanges.xml --wait 30 --testlevel RunLocalTests

8. Incorporate Continuous Integration and Continuous Delivery (CI/CD)

Development based on Git enables the implementation of various automation alternatives, such as carrying out code checks and performing frontend or unit tests.

The options are vast. Nevertheless, it is wise to commence with basic automation capabilities and progressively enhance them.
👨‍🍳
The requirements and preferences for CI/CD are unique and may differ depending on the project. Several exceptional open-source instances can be used as a source of inspiration for adoption. At Hutte, for example, we are creating a "Recipe" gallery that will offer an excellent starting point for your CI/CD requirements.

Make the switch to Hutte for your Git-Based Development

Hutte has made Git-based development accessible to everyone, including non-technical members of product teams.

It simplifies the creation and management of scratch orgs and sandboxes, enabling developers to spend more time coding and less time manually creating developer orgs via the CLI.

Hutte offers an easy-to-use interface on the frontend while providing a powerful backend to help development teams take advantage of the benefits of Git-based development.

🚢
It essentially allows teams to build and ship work on the Salesforce platform more efficiently. Through the UI, anyone on a team can create and log into a Salesforce environment in one click without sharing credentials.

There, teams can perform no-code work and create a pull request – all in a no-code way. Meaning, even if you (or your team) don't know code, you can still generate development projects.

Users and teams don't need to learn how to install and use command-line tooling and Git.

Creating scratch orgs usually takes hours of developers' time every week. That’s why Hutte is a huge time-saver, as you can take a fully prepared development environment from the pool within a few seconds. This enables Hutte to boost teams' productivity daily.


Sign up for Hutte

Git is here to stay

The world of Git-based Salesforce development is where code collaboration and version control go hand in hand.

Git-based Salesforce development aims to bridge the gap between the powerful Salesforce platform and the robust version control system, Git.

This partnership enables you to:

  • Track changes
  • Collaborate more effectively with your team
  • Ensure that your codebase is stable, organized, and easy to maintain.

This makes it the ultimate alliance.

😴
By incorporating Git into your Salesforce development process, you'll unlock a new level of efficiency and collaboration, avoiding conflicts, lost changes, or sleepless nights resolving disputes. 

Instead, you'll be working with development with Git-powered version control backing you up. But it can be pretty daunting to adopt Git if you don’t have the right third-party tool to help you.

As previously stated, Hutte facilitates code and no-code development, eliminating the complexity of a command-line interface and Git. With Hutte, you can maintain complete transparency and flexibility, making it an ideal solution for Salesforce development teams.

So, why not give Git-based Salesforce development a chance and start enjoying the benefits of this perfect match in coding utopia?


Spring Release Updates
Automation with Einstein Copilot
This release allows for the automation of tasks using AI-driven prompts that can be integrated with Git-based development workflows. This makes it easier for developers to automate repetitive tasks directly within their development environment.
Prompt Builder
The Prompt Builder feature lets users create, test, and refine AI-driven prompt templates without coding. This can be particularly useful in Git-based development for managing merge requests and commits by automating parts of the process using AI.

Last updated: 11 Jul 2024