Automatically create master branch on repository creation?

Is it possible to use automatically create a branch when a repository is created? We've configured all our repositories to reject force push and push to master to require pull requests, but you can't make a pull request to a branch that doesn't exist.

1 answer

0 vote

The problem is that in git, branches are just references that point to commits, so you can't have a branch without any commits.

The closest I can think of, is to create an empty commit in the bare repo on the server, then create master pointing to it.

The following event handler will do it, if you have it listen to RepositoryCreatedEvent. Note you need to refresh the page after creation to see that the branch has been created.

https://gist.github.com/jechlin/6365d2e3c0ef4b94deb636db9c2cde7d

Also note that the common workflow for devs is to create a repo locally, work, decide that they should share it. Then they create a repo in BBS and push to it. I think creating the branch and commit will not allow that, but untested.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

357 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you