How to automate merging a branch in CI job?

Replace this template with your information

Describe your question in as much detail as possible:

My goal is to automatically merge branch main into a release branch after the CI pipeline succeeds.
I’m not sure where to start because stack overflow says to use a private SSH key to run git commands inside the job, but then some articles say to use an API token and use GitLab push events?

Is there any documentation on this or is there an easier way to achieve this in GitLab?

  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?