This action deletes a specified Neon branch by its name within your Neon project.
It simplifies deleting Neon branches when you only know the branch name and not its ID. It internally retrieves the branch ID using the provided name and then utilizes the Neon Delete Branch Action to perform the deletion.
Using the action requires adding a Neon API key to your GitHub Secrets. There are two ways you can perform this setup:
-
Using the Neon GitHub Integration (recommended 👍) — this integration connects your Neon project to your GitHub repository, creates an API key, and sets the API key in your GitHub repository for you. See Neon GitHub Integration for instructions.
-
Manual setup — this method requires obtaining a Neon API key and configuring it manually in your GitHub repository.
- Obtain a Neon API key. See Create an API key for instructions on the Neon documentation.
- In your GitHub repository, go to Settings and locate Secrets and variables at the bottom of the left sidebar.
- Click Actions > New repository secret.
- Name the secret
NEON_API_KEY
and paste your API key in the Value field. - Click Add secret.
The following fields are required to run the Delete Branch by Name action:
project_id
— The Neon project ID. If you have the Neon GitHub Integration installed, you can specify${{ vars.NEON_PROJECT_ID }}
. You can find the project ID of your Neon project on the Settings page of your Neon console.api_key
— The Neon API key for your Neon project or organization. If you have the GitHub integration installed, specify${{ secrets.NEON_API_KEY }}
.branch_name
— The name of the Neon branch you want to delete.
Setup the action in your workflow:
steps:
- uses: neondatabase/delete-branch-by-name-action@main
with:
project_id: your_neon_project_id
branch_name: my-old-feature-branch # Specify branch name to delete
api_key: ${{ secrets.NEON_API_KEY }}
Alternatively, you can use ${{ vars.NEON_PROJECT_ID }}
to get your project_id
. If you have set up the Neon GitHub Integration, the NEON_PROJECT_ID
variable will be defined as a variable in your GitHub repository.
This action internally performs the following steps:
- Retrieves Branch ID: It uses the Neon API to find the branch ID associated with the provided
branch_name
. - Deletes Branch: It then utilizes the Neon Delete Branch Action to delete the branch using the retrieved
branch_id
.
This action does not provide any outputs. The primary function is to delete a Neon branch by its name.
Here's an example of a complete GitHub Actions workflow that deletes a Neon branch by name:
name: Neon Github Actions Delete Branch by Name
on:
# You can modify the following line to trigger the workflow on a different event, such as `push` or `pull_request`, as per your requirements. We have used `workflow_dispatch` for triggering the action in this example.
workflow_dispatch:
jobs:
Delete-Neon-Branch-By-Name:
runs-on: ubuntu-24.04
steps:
- uses: neondatabase/delete-branch-by-name-action@main
with:
project_id: ${{ vars.NEON_PROJECT_ID }}
branch_name: my-old-feature-branch # Replace with the branch name you want to delete
api_key: ${{ secrets.NEON_API_KEY }}
- run: echo "Branch 'my-old-feature-branch' deleted successfully"
Check out other Neon GitHub Actions: