After the first release of our product, we will be switching to a different branches for the main development and feature development. Is there a way to create a branch in such
You can use branch permissions on the server by adding a pre-receive hook that protects your repository and add something like this to your config file in your bare repository:
[hooks]
allowedtomerge = user1,user2,user3
protectedbranches = master
If you are using Gitlab then you can configure protected branches:
Configuring protected branches
To protect a branch, you need to have at least Master permission level. Note that the master branch is protected by default.
Navigate to your project's Settings ➔ Repository
Scroll to find the Protected branches section.
[...]
There are many ways to tackle this:
I have a git branch model which has dev/master/production branches used for staged deployments, so there are branches that I want protected against deletion. I use pull requests and Visual Studio Team Services, so after each pull request from dev to master for example, VSTS would ask if I would like to delete the source branch (dev).
I was worried about a developer accidentally deleting dev or another important branch which is used for deployments so I used this hack:
I created a branch off of dev called "save", made a one line change, opened a pull request against dev, and just leave it open.
As long as there is an open pull request against dev, dev cannot be deleted and VSTS will not ask if I would like to delete the branch.
If there is any other more official solution to this problem, I'd be happy to use it. But for now, this was easy and works.
Since the OP shershams mentioned in the comments
we're planning to switch to github and I was wondering if they have something implemented there for this purpose
It turns out there is something implemented (and available soon) in GitHub:
Protected branches and required status checks (September 3, 2015) will allow you to protect a branch:
Note that, since Dec. 4th 2019, you can grant all users with push access the ability to delete a protected branch by enabling Allow deletions
.