How To Protect a GIT branch (like master)
Asked Answered
I

4

6

I'm comfortable doing GIT branching and merging but want to know how I can allow a new developer who is not comfortable with merging and branching to not accidentally hurt a release or production branch (like master for example).

What is a good workflow so that a developer who is doing lots of commits can get his updates synced with a master or some other branch. That is, without the new developer having commit privileges to that branch.

Inordinate answered 6/6, 2013 at 23:49 Comment(1)
possible duplicate of A way to restrict Git branch access?Coy
S
1

Simply don't give the developer commit permissions on the master/branch. They can fork the repository and submit pull requests to get their changes back to the master.

Stets answered 7/6, 2013 at 0:4 Comment(0)
C
6

Git is pretty well-suited to this due to its decentralised nature. I'd suggest that you ask the other developer to fork your repo and then create a pull request whenever they've finished a new feature that they want you to merge. You can then look at the commits attached to each pull request and decide whether or not to merge them into the main repo.

Once the other developer knows what they're doing, you can always give them commit rights to the main repo and ask them to delete their fork.

Choriamb answered 7/6, 2013 at 0:1 Comment(0)
C
3

You can avoid a Fork and Pull model by using the protected branches functionality that restricts pushes to a branch in an Organization to specific users or teams. This will allow you to add all 'trusted' developers to a team that can merge/push to a branch.

branch restriction gif

Additionally, if you use GitHub Enterprise that offers pre-receive hooks, you can enable one that enforces all code to be merged through a PR

Chamblee answered 11/12, 2016 at 22:17 Comment(0)
S
1

Simply don't give the developer commit permissions on the master/branch. They can fork the repository and submit pull requests to get their changes back to the master.

Stets answered 7/6, 2013 at 0:4 Comment(0)
O
0

This isn't really something git can do. Git doesn't handle permissions... However take a look at gitolite, it will do this for you.

Octosyllabic answered 7/6, 2013 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.