---
schema_version: "1"
id: 27eee174756cef8239de02cfca132010bfd9481a95dfb633027fe7044aac414b
title: Use Branches in Second-Generation Managed Packaging
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform-pkg-exchange/managed_packaging/guides/second-generation/sfdx-dev-dev2gp-use-branches.md
canonical_url: https://developer.salesforce.com/docs/platform/pkg2-dev/guide/sfdx-dev-dev2gp-use-branches.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7719ddfc0e2282f8a648c28fa38b67f81f351078abda7bec1a50c0ab81261df8
products:
  - Second-Generation Managed Packaging Developer Guide
  - merged-docs
---

# Use Branches in Second-Generation Managed Packaging

Development teams who use branches in their source control system (SCS), often build package versions based on the metadata in a particular branch of code.

To identify which branch in your SCS a package version is based on, tag your package version with a branch name using `--branch` attribute in this Salesforce CLI command.

`sf package version create --branch featureA`

You can specify any alphanumeric value up to 240 characters as the branch name.

You can also specify the branch name in the package directories section of the `sfdx-project.json` file.

```nolang
"packageDirectories": [
     {
        "path": "util",
        "default": true,
        "package": "pkgA",
        "versionName": "Spring ‘21",
        "versionNumber": "4.7.0.NEXT",
        "branch": "featureA"
     }]

```

When you specify a branch, the package alias for that package version is automatically appended with the branch name. You can view the package alias in the `sfdx.project.json` file.

```nolang
"packageAliases": {
    "pkgA@1.0.0.4-featureA":"04tB0000000IB1EIAW"}
```

Keep in mind that version numbers increment within each branch, and not across branches. For example, you could have two or more beta package versions with the version number 1.3.0.1.

| Branch Name   | Package Version Alias |
| ------------- | --------------------- |
| featureA      | pkgA@1.3.0-1-featureA |
| featureB      | pkgA@1.3.0-1-featureB |
| Not specified | pkgA@1.3.0-1          |

Although more than one beta package version can have the same version number, there can be only one promoted and released package version for a given major.minor.patch package version.

## Package Dependencies and Branches

By default, your package can have dependencies on other packages in the same branch. For package dependencies based on packages in other branches, explicitly set the branch attribute in the `sfdx.project.json` file.

| To specify a package dependency                                                           | Use this format                   |
| ----------------------------------------------------------------------------------------- | --------------------------------- |
| Using the branch attribute                                                                | See the example after this table. |
| Using the most recent promoted and released version of package                            | See the example after this table. |
| If your package has an associated branch, but the dependent package doesn’t have a branch | See the example after this table. |
| Using the package alias                                                                   | See the example after this table. |

Example: Using the branch attribute

```nolang
"dependencies": [
    {
    "package": "pkgB",
    "versionNumber": "1.3.0.LATEST",
    "branch": "featureC"
}]

```

Example: Using the most recent promoted and released version of package

```nolang
"dependencies": [
    {
    "package": "pkgB",
    "versionNumber": "2.1.0.RELEASED"
}]

```

Example: Dependent package has no branch

```nolang
"dependencies": [
     {
    "package": "pkgB",
    "versionNumber": "1.3.0.LATEST",
    "branch": ""
}]

```

Example: Using the package alias

```nolang
"dependencies": [
     {
    "package": "pkgB@2.1.0-1-featureC"
}]

```
