# Understanding Branches for Salesforce projects

When you create an analysis project from Salesforce, the org or sandbox you authorize will become your main branch. You can add your sandboxes as analysis project branches by editing your project (from the **Project Analysis** page). This allows for easy comparison between the production orgs or sandboxes and is especially good for checking features before production.

1. Select your Salesforce project from the **My Projects** screen.
2. Go to the **More** tab and select **Project Analysis** from the dropdown.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2F1BI5zPeplUEar0d9zyHF%2FPA%204.6.png?alt=media&#x26;token=cdea25a9-306b-4931-ab46-25a9e8abcde8" alt="" width="563"><figcaption></figcaption></figure>

2. Click on **Edit Project**.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FLrVkBmBRpXPu4xhwdwS6%2FPA%20Edit%204.7.png?alt=media&#x26;token=2b506f7d-8f2f-4146-a4a6-b3ae73c16e39" alt="" width="563"><figcaption></figcaption></figure>

3. Click on![](https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FkdU66gHq6LQkL9MhQJcd%2Fimage.png?alt=media\&token=fe59061d-0f6a-481f-b877-7d29337de833)button to add a new branch.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FQsDDe08kv6YLNRWMjPWf%2FSFAddBranch%204.8.png?alt=media&#x26;token=2299c1fb-280c-4df3-9e6e-3c58cf393873" alt=""><figcaption></figcaption></figure>

4. Assign a name to your branch and choose the branch type:

* **Comparison Branch:** This branch determines only the recent issues in a project branch based on comparing with the standard branch in your project.
* **Standard Branch:** This branch will have your project's entire history and dashboards.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FhIrlhFuQIElgySDC0Soz%2FSFNewBranch%204.9.png?alt=media&#x26;token=a98a3b64-ef36-4474-831a-4a8434849f83" alt="" width="563"><figcaption></figcaption></figure>

5. Select your Salesforce environment.
6. Once you click on **Authorize**, it will redirect you to the Salesforce login page to validate your credentials.
7. This triggers the project analysis and the project being added under your CodeScan organization.
8. You'll be redirected to the **Project Analysis** screen, where you can view the status of your triggered analysis.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FcU6dZ2Uw5KQE3CJH1kva%2FNBAnalyisi%205.0.png?alt=media&#x26;token=8ae86f9e-604d-4439-a49f-d0c70b648bee" alt=""><figcaption></figcaption></figure>

### Features of a comparison branch <a href="#features-of-a-comparison-branch" id="features-of-a-comparison-branch"></a>

When you create a comparison branch, the issues shown are only the new ones in that branch, not the general issues you see in the project's main branch.

The property below is responsible for changing the UI labels and texts from *Pull Requests* to *Comparison Branches*.

```
codescan.comparison.branches
```

{% hint style="info" %}
**Note:** The `codescan.comparison.branches` property is in OFF state by default.
{% endhint %}

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2Fq94cqNtaQxlpfXTEQNEV%2FSettingBranch%205.1.png?alt=media&#x26;token=6e13b6e6-547b-4462-8053-11f1d427df04" alt=""><figcaption></figcaption></figure>

The comparison branches feature is enabled automatically when you:

* create new comparison branch via CodeScan user interface inside project with Salesforce as the integration type or,
* run sonar-scanner or CodeScan SFDX utility with these two new scanner properties:

> -Dsonar.comparison.branch=...\
> -Dsonar.comparison.base=...

Another way is via **AutoRABIT-CodeScan** integration.

The new properties `sonar.comparison.branch` and `sonar.comparison.base` are equivalents/aliases of these existing two: `sonar.pullrequest.branch` and `sonar.pullrequest.base`.

So, because they are equivalents - the logic will be the same. If you mark any issue as `False Positive` or `Resolve as Won't fix` in your Comparison Branch, then this issue will not re-appear in the project's main branch after changes are merged.\
Similarly, the new comparison branches reflect the changes on issues made by the user on the project’s main branch.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FAjsAW94Gv0XAd3ganLEA%2FIssues%20Main%20Page.png?alt=media&#x26;token=5b8f69e4-f45a-4555-9f5c-084871df2787" alt=""><figcaption></figcaption></figure>

To test the new feature using sonar-scanner:

1. Execute the initial analysis on base branch using the below command:

```
sonar-scanner -Dsonar.host.url=https://app.codescan.io -Dsonar.organization=<org-id>
-Dsonar.projectKey=<project-key> -Dsonar.login=<security-token>
```

2. Execute analysis on a comparison branch:

```
sonar-scanner -Dsonar.host.url=https://app.codescan.io -Dsonar.comparison.branch=<comparison-branch-name>
-Dsonar.comparison.base=<base-branch-name> -Dsonar.organization=<org-id> -Dsonar.projectKey=<project-key>
-Dsonar.login=<security-token>
```

### Managing branches <a href="#managing-branches" id="managing-branches"></a>

On your **Project Analysis** page, go to **Project Setting > Branches**.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2Fk1EbEY4SrYgVGF8ankRO%2FBranches%205.2.png?alt=media&#x26;token=49005e9b-ea2c-42e7-b25c-f03917cee6be" alt="" width="375"><figcaption></figcaption></figure>

On this page, you can:

* View the branches you have created and segregated into master branches (including standalone branches) and comparison branches in two different tabs.
* Delete all the branches except the main branch.
* Renaming of the branch applies only to the main branch.

#### Delete a branch <a href="#delete-a-branch" id="delete-a-branch"></a>

For example, to delete a comparison branch, navigate to the **Comparisons Branches** tab, click on <img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FCRXYuIlmwlxitHw87zC2%2Fimage.png?alt=media&#x26;token=3e6b4735-c51a-4bba-bb03-c0fe8e058a7e" alt="" data-size="line">icon and click on **Delete Comparison Branch**. Note that this process cannot be undone.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FKu6QEDyJtKxgwIv3jCQD%2Fimage.png?alt=media&#x26;token=c4d778ed-e4a2-4d72-92b6-52c5606e38e2" alt=""><figcaption></figcaption></figure>

#### Rename the main branch <a href="#rename-the-main-branch" id="rename-the-main-branch"></a>

To update the name of the main branch, navigate to the **Branches** tab, and look for the main branch.\
Click on <img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FX2bzSwIkC2DTOtQJabPx%2Fimage.png?alt=media&#x26;token=77ecb9c9-dd56-4e4a-be63-3692b3ffd205" alt="" data-size="line">icon under the **Actions** tab and click on **Rename branch**.

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FzNDTRp0sLxRb49FgIaBq%2FRename%20Main.png?alt=media&#x26;token=53bb9b00-9adc-4de4-8e73-dac168f5d1c0" alt=""><figcaption></figcaption></figure>

Give the main branch a new name and click on **Rename**.

### Comparing Branches <a href="#comparing-branches" id="comparing-branches"></a>

<figure><img src="https://1912836914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9vAxMuDrkUkB4OXlH9CL%2Fuploads%2FczanJ7gGBbPrFBnuezFN%2FComparision.png?alt=media&#x26;token=88df99d8-1849-438a-9600-d59c80d2b60f" alt="" width="563"><figcaption></figcaption></figure>

1. Select your Salesforce project from the **My Projects** page.
2. When you click on the main branch dropdown for your project, you can see the list of all branches that you have created or added.
3. If there are any violations for your branch, such details will appear. If you click on a branch, the details of the violations can be seen on the **Quality Gate Status** screen.

{% hint style="info" %}
**Important Note:**&#x20;

All new branches added in this way will be deleted in **30 days** if they are not analyzed again. If you have any further questions about CodeScan Cloud, please [contact us](https://www.codescan.io/contact/).
{% endhint %}
