• Documentation
  • Pricing
© 2026 Serverless, Inc. All rights reserved.

Framework

  • Overview
  • Documentation
  • Plugins360
  • Pricing

Learn

  • Blog
  • GuidesUpdated
  • Examples240
  • Courses

Resources

  • Support
  • Security
  • Trust Center
  • Status

Community

  • Slack
  • GitHub47k
  • Forum
  • Meetups

Company

  • About
  • Careers
  • Contact
  • Partners

Legal

  • Terms of Service
  • Privacy Policy
  • Trademark
  • DMCA
Serverless Framework Logo

Serverless Framework

Intro
SetupUpgrading To V4ConceptsTutorialAWS CredentialsLicense KeysVerifying Downloads
DeployingPackagingBuildingTestingDev ModeServicesFunctions
OverviewHTTP (API Gateway v2)REST (API Gateway v1)ActiveMQApplication Load BalancerAlexa SkillAlexa Smart HomeCloudWatch EventCloudWatch LogCloudFrontCognito User PoolEventBridge EventIoTIoT Fleet ProvisioningKafkaKinesis & DynamoDBMSKRabbitMQS3ScheduleSNSSQSWebsocket
Layers
OverviewTroubleshooting
Managed InstancesWeb Apps (Lambda Web Functions)Sandboxes (Lambda MicroVMs)MCP ServersAlertsVersion PruningDomainsIAM Function PermissionsParameters
OverviewSelf-reference serverless.ymlServerless CoreEnvironment VariablesCLI OptionsExternal YAML/JSON FilesJavascript propertiesGitDoppler
OverviewS3 ObjectsSSM Parameter Store & Secrets ManagerCloudFormation Stack Outputs
OverviewVaultTerraform State Output
ResourcesComposing ServicesDeployment BucketStateAgent SkillsPython support
OverviewRuntimeGatewayMemoryBrowserCode InterpreterDev Mode
API Gateway Proxy
OverviewGeneral ConfigurationAuthenticationAPI KeysData SourcesResolversPipeline FunctionsSubstitutionsCachingDelta SyncCustom DomainWAFCLI Commands
Deploying SAM/CFN TemplatesWorkflow Tips
OverviewCreating PluginsCLI OutputCustom CommandsCustom VariablesExtending the Configuration schemaExtending and overriding configuration
OverviewDashboardAxiom
Overviewagent docsagent inspectagent setupagent skills installagent skills list / readdeploydeploy functiondeploy listdevdiffinfoinvokeinvoke localloginlogin awslogin aws ssologsmetricspackageplugin installplugin uninstallprintprunereconcileremoverollbackrollback functionusage
OverviewConcepts
OverviewMetricsTracesTroubleshoot
OverviewNode.jsPython
OutputsProviders
OverviewBranch DeploymentsPreview DeploymentsCustom ScriptsTestingPrivate PackagesNotificationsMono ReposDeploy in your own CI/CDBest PracticesTroubleshootingFAQ
OverviewSetupToolsAWS Integration
Serverless.yml Reference
Examples and TutorialsConfiguration Validation
  1. Usage
  2. Variables
  3. Git

Git Variables

A ${git:NAME} variable inserts information about the Git repository that contains serverless.yml, such as the current commit hash, branch or tag, into the configuration. Use it to label a deployment with the code it came from, for example in resource tags, a function description or an environment variable that reports the version.

The following serverless.yml tags every function with the commit and branch, sets the function description to the commit subject, and passes the nearest tag to the function as APP_VERSION:

# serverless.yml
service: my-service

provider:
  name: aws
  runtime: nodejs24.x
  tags:
    GIT_COMMIT: ${git:sha1}
    GIT_BRANCH: ${git:branch}

functions:
  hello:
    handler: handler.hello
    description: ${git:messageSubject}
    environment:
      APP_VERSION: ${git:describeLight}

The Framework runs git in the directory that contains serverless.yml, so git must be installed and that directory must be inside a Git repository.

Syntax of the git variable

${git:NAME}

NAME (required) is one of the names in Available git variables. Every git variable returns a string, with leading and trailing whitespace removed.

Available git variables

NameValueExampleGit command
sha1The short hash of the current commit1f769ecgit rev-parse --short HEAD
commitThe full hash of the current commit1f769ecaa84729fa90ef1f3527a6f1df1e3072cfgit rev-parse HEAD
branchThe current branch, or HEAD in a detached-HEAD checkoutmaingit rev-parse --abbrev-ref HEAD
describeThe nearest annotated tag, with the commits since it and the short hash when the commit isn't tagged; the short hash when there's no annotated tagv1.0.0-1-g1f769ecgit describe --always
describeLightLike describe, but also uses lightweight tagsv1.0.1git describe --always --tags
tagsThe tags on the current commit, joined with ::; the short hash when the commit has no tagsv1.0.0::latestgit tag --points-at HEAD
messageThe full message of the current commitAdd file uploadgit log -1 --pretty=%B
messageSubjectThe first line of the commit messageAdd file uploadgit log -1 --pretty=%s
messageBodyThe commit message after the subject; an empty string when there's noneValidates the file size.git log -1 --pretty=%b
useruser.name from the Git configurationJane Doegit config user.name
emailuser.email from the Git configurationjane@example.comgit config user.email
isDirty'true' when tracked files have unstaged changes, otherwise 'false''false'git diff --stat
repositoryThe name of the repository's top-level directory on disk, not the name of the remotemy-servicegit rev-parse --show-toplevel

Through v4.46.0, isDirty returns 'false' in every case.

CI systems often check out a commit without a branch, so ${git:branch} returns HEAD there. To get the branch name in CI, read the variable your CI system sets, for example ${env:GITHUB_REF_NAME} in GitHub Actions.

Where to use git variables

Git values can contain characters that some AWS settings reject, so check the target setting's rules:

  • Branch names often contain / (feature/login), which Lambda function names and many resource names don't allow. Resource tags allow it.
  • A commit message can span several lines and run long, while a Lambda function description is limited to 256 characters. messageSubject fits more often than message.

A value that changes with every commit, such as sha1 in an environment variable, changes the function's configuration on every deployment, so the Framework updates the function each time.

Errors from git variables

When a git command exits with an error, the Framework stops and shows the command's output, for example outside a Git repository:

Failed to resolve variable 'branch' with resolver 'git' and provider 'git': Error: Command failed: git rev-parse --abbrev-ref HEAD
fatal: not a git repository (or any of the parent directories): .git

${git:user} and ${git:email} stop the same way when user.name or user.email isn't set in the Git configuration. A default value after a comma (${git:branch, 'local'}) isn't used when the git command exits with an error; to deploy from a directory that might not be a Git repository, use a source that is always available, such as ${env:...} with a default.

A name that isn't in Available git variables stops the command with:

Git variable foo is unknown. Candidates are 'describe', 'describeLight', 'sha1', 'commit', 'branch', 'message', 'messageSubject', 'messageBody', 'user', 'email', 'isDirty', 'repository', 'tags'

Related variable sources

  • Variables: how variables work, and the list of all variable sources.
  • Environment variables: read values your CI system sets, such as the branch name.
  • Serverless Core variables: the stage and a per-run instance ID.
  • git describe in the Git documentation: how describe and describeLight name a commit.
Edit this page
Prev Javascript propertiesNextDoppler

Contents

  • Git Variables
  • Syntax of the git variable
  • Available git variables
  • Where to use git variables
  • Errors from git variables
  • Related variable sources

Related

GuidesPluginsExamplesSlack CommunitySupport