Git Error 'You are not currently on a branch' in Bash Script on Bitrise"

I’ve created a Bash script to run SwiftFormatter, and if there are changes, it commits and pushes them to the current branch. However, when trying to push, I get this error: “You are not currently on a branch.”

I’ve already set up Git credentials, so I don’t think that’s the issue. Has anyone faced this before or knows how to fix it?