Peter Kellner
Peter Kellner

Reputation: 15488

How To Protect a GIT branch (like master)

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.

Upvotes: 6

Views: 9710

Answers (4)

osowskit
osowskit

Reputation: 6344

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

Upvotes: 3

iveqy
iveqy

Reputation: 24291

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.

Upvotes: 0

Paul Anderson
Paul Anderson

Reputation: 1180

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.

Upvotes: 1

user269597
user269597

Reputation:

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.

Upvotes: 6

Related Questions