I am new with GIT and branching and recently I saw protected
branch, what does that mean and how do we protect a branch?
-
6*Protected* is not a Git property, it's implemented (differently!) by various hosting servers. (Hence you need to specify which hosting server you're interested in.) Fortunately they are all pretty broadly similar, at least so far, as far as I know, as of end-of-2017, at least. – torek Dec 30 '17 at 01:19
-
4On how to protect branch in a local implementation, each hosting service would give their solution. This should help: `https://stackoverflow.com/questions/2471340/is-there-a-way-to-lock-a-branch-in-git` – pradosh nair Dec 30 '17 at 01:48
-
@torek thank you, i fought of protected as part of git, any documentantion about hosting servers, I am cofused about all (Github, GitLab etc..), and then comes `Git` it's a little confusing, could you configute your own server so that you can upload projects using git and ttherefore configure custom branch protection? – Dec 30 '17 at 02:05
-
2Yes, you can configure your own Git servers. The setup is a little complex, which is why providers like GitHub exist and can make money selling service. Handling a corporate Git environment (I used to be involved in running one) can, depending on requirements, take one or more positions in an IT department. – torek Dec 30 '17 at 06:19
2 Answers
It's not a feature of git but a feature of Github and other code hosting sites. It allows you to protect specific branches from unauthorized modification.
Here's the Github documentation::
Protected branches ensure that collaborators on your repository cannot make irrevocable changes to branches. These branches can also be protected by requiring pull requests to have at least one approved review before they can be merged.
If you own a repository with multiple collaborators who create branches and open pull requests, you may need to enforce branch protections to keep your project and pull requests organized and safe.
Protected branches block several features of Git on a branch that a repository administrator chooses to protect. A protected branch:
Can't be force pushed
Can't be deleted
Can't have changes merged into it until required status checks pass
Can't have changes merged into it until required reviews are approved Can't be edited or have files uploaded to it from the web
Can't have changes merged into it until changes to files that have a designated code owner have been approved by that owner If your repository belongs to an organization, you can restrict users or teams from pushing to a protected branch.
The specific details will vary depending on the website you use.

- 3,571
- 21
- 32
-
thank you but I wanted stackoverflow's explanation, and this doesn't answer my question entirely (how do we protect a branch). – Dec 30 '17 at 00:47
-
2@RJeremy The answer depends on the hosting site (Github, Bitbucket, Gitlab, etc). Branch protection is a feature of those hosting sites, not of Git itself. The above answer is quoting from documentation specific to Github. – Dan Lowe Dec 30 '17 at 00:54
-
how can you make it so that the branch protection applies to only one person? – Arjun Apr 30 '19 at 21:26
tools like github, gitlab etc. gives you an option to protect branches against accidental messing ups. non authorized users cannot push changes to protected branches

- 166
- 2
- 7
-
1to protect branches in github go to project settings/branches. ın gitlab go to project settings/repository – serdroid Dec 30 '17 at 00:53