Delete Git Branch


I was wondering if there is an option to delete a branch after a merge build is finished in Circle CI. From what I saw, we only have available a CIRCLE_BRANCH env variable, which provides the name of the branch being built, but I am interested in the branch being merged, so that I can trigger a branch delete from inside the the config.yml file.

Thank you :slight_smile:

This is something that normally is handled automatically, but sometimes doesn’t happen for unknown reasons. The ability to manually delete them is a feature request being tracked here

I think I was not explicit enough. I want to perform a

git push <remote_name> --delete <branch_name>

so that I can remove from Git the branch that I have merged.

Ah, my apologies, I thought you meant something else.

You would need to create a Machine User for this since the default keys we generate only have read access.

Thanks for the information. And how can I determine the branch that was merged in Git from the build that is running?

Is there an ENV variable that could tell me the name of that branch?


We expose the following environmental variables that may help you

If you search or ask here on the forums I know some other members have used git commands to extract other data that may be helpful, if our built-in envs doesn’t fit your needs.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.