Commit can be done as the official document https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-7.2&tabs=HTTP.
I tested your code and get the same error.But after change to latest version to "api-version=7.2-preview.3" it works.
I think it is because they didn't fix the old preview vesion anymore. Cause "api-version=7.1" also works.