Currently, I am working on a tool that creates a repository in a bitbucket project and populates it with files from a template after some processing. I have been asked to add a feature that changes the default branch from master to main.
-
repo.git.execute(['git', 'checkout', '-b', 'main'])
-
response = requests.put(" /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches/default", auth=HTTPBasicAuth(<username>, <password>), data='id=main')
-
repo.create_head('main').checkout()
Above are a few attempts that I made to create or change to a new default branch, with varying degrees of success. Below are links to the documentation that I have been following as I build the tool.
https://docs.atlassian.com/bitbucket-server/rest/7.17.3/bitbucket-rest.html#idp186
https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branching-model/
I have some additional documentation to share but, if there is a more simple manner to implement this feature, you have documentation that I haven’t yet come across, or can offer any assistance, please do not hesitate to reach out.