Initialize Git Repository

Action ID: git
NPM Package:

@mdude2314/backstage-plugin-scaffolder-git-actions

Description

Initializes a Git repository and sets up version control for your project.

Input Schema

PropertyTypeDescriptionRequired
argsarray-
commandstringThe git command to run
workingDirectorystringWorking directory within the scaffolder workspace to execute the command in

Output Schema

No output schema defined for this action.

Usage Examples

Initialize a repository and make the first commit

Use this to initialize a new Git repository for the scaffolded content and create the initial commit. Run after fetching your template with fetch:template.

Copy
steps:
  - id: fetch
    action: fetch:template
    name: Fetch service template
    input:
      url: https://github.com/acme/templates/node-service
      targetPath: ./${{ parameters.repoName }}
      values:
        name: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}

  - id: git_init
    action: git
    name: Init git repo
    input:
      command: init
      workingDirectory: ./${{ parameters.repoName }}

  - id: git_add_all
    action: git
    name: Stage all files
    input:
      command: add
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "."

  - id: git_commit_initial
    action: git
    name: Initial commit
    input:
      command: commit
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-m"
        - "chore: initial scaffold for ${{ parameters.repoName }}"

Configure repository-local Git user before committing

Set repository-local user.name and user.email to ensure commits from the scaffolder have a clear author. Useful in CI environments where global Git config is not set.

Copy
steps:
  - id: fetch
    action: fetch:template
    name: Fetch template
    input:
      url: https://github.com/acme/templates/go-service
      targetPath: ./${{ parameters.repoName }}
      values:
        name: ${{ parameters.repoName }}

  - id: git_init
    action: git
    name: Init git repo
    input:
      command: init
      workingDirectory: ./${{ parameters.repoName }}

  - id: git_config_name
    action: git
    name: Set user.name
    input:
      command: config
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - user.name
        - Scaffolder Bot

  - id: git_config_email
    action: git
    name: Set user.email
    input:
      command: config
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - user.email
        - scaffolder-bot@acme.example

Create and switch to a feature branch

Create a feature branch after scaffolding to isolate subsequent modifications. This is typically done after initialization.

Copy
steps:
  - id: fetch
    action: fetch:template
    name: Fetch template
    input:
      url: https://github.com/acme/templates/python-service
      targetPath: ./${{ parameters.repoName }}
      values:
        name: ${{ parameters.repoName }}

  - id: git_init
    action: git
    name: Init git repo
    input:
      command: init
      workingDirectory: ./${{ parameters.repoName }}

  - id: git_checkout_branch
    action: git
    name: Create feature branch
    input:
      command: checkout
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-b"
        - "feature/${{ parameters.ticketId }}-bootstrap"

Add a remote and push the main branch

Add the origin remote and push the main branch to your Git host. Use after an initial commit so there is content to push.

Copy
steps:
  - id: fetch
    action: fetch:template
    name: Fetch template
    input:
      url: https://github.com/acme/templates/java-service
      targetPath: ./${{ parameters.repoName }}
      values:
        name: ${{ parameters.repoName }}

  - id: git_init
    action: git
    name: Init git repo
    input:
      command: init
      workingDirectory: ./${{ parameters.repoName }}

  - id: git_add
    action: git
    name: Stage files
    input:
      command: add
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "."

  - id: git_commit
    action: git
    name: Commit files
    input:
      command: commit
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-m"
        - "feat: bootstrap ${{ parameters.repoName }}"

  - id: git_rename_main
    action: git
    name: Rename default branch to main
    input:
      command: branch
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-M"
        - "main"

  - id: git_add_remote
    action: git
    name: Add origin remote
    input:
      command: remote
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - add
        - origin
        - ${{ parameters.repoUrl }}

  - id: git_push_main
    action: git
    name: Push main to origin
    input:
      command: push
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-u"
        - origin
        - main

Tag a release and push tags

Create an annotated tag for a release and push tags to the remote. Use this when cutting a release after your changes are committed.

Copy
steps:
  - id: fetch
    action: fetch:template
    name: Fetch template
    input:
      url: https://github.com/acme/templates/ts-lib
      targetPath: ./${{ parameters.repoName }}
      values:
        name: ${{ parameters.repoName }}

  - id: git_init
    action: git
    name: Init git repo
    input:
      command: init
      workingDirectory: ./${{ parameters.repoName }}

  - id: git_add_remote
    action: git
    name: Add origin remote
    input:
      command: remote
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - add
        - origin
        - ${{ parameters.repoUrl }}

  - id: git_tag
    action: git
    name: Create annotated tag
    input:
      command: tag
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "-a"
        - "v${{ parameters.version }}"
        - "-m"
        - "Release v${{ parameters.version }}"

  - id: git_push_tags
    action: git
    name: Push tags
    input:
      command: push
      workingDirectory: ./${{ parameters.repoName }}
      args:
        - "--tags"
        - origin