Gitflow: Disallow direct commits to master

Created on 12 Jul 2013  ·  17Comments  ·  Source: nvie/gitflow

In order to follow Git-Flow, we should disallow direct commits to the master branch, with the intention that users should use releases or hotfixes to commit to the master branch.

Most helpful comment

To disallow commits on master edit the hook file pre-commit in the hooks directory.

Add the following code to be run first:

branch=`git symbolic-ref HEAD`
if [ "$branch" = "refs/heads/master" ]; then
    echo "Direct commits to the branch master are not allowed"
    exit 1
fi

All 17 comments

I agree with you.

To disallow commits on master edit the hook file pre-commit in the hooks directory.

Add the following code to be run first:

branch=`git symbolic-ref HEAD`
if [ "$branch" = "refs/heads/master" ]; then
    echo "Direct commits to the branch master are not allowed"
    exit 1
fi

@petervanderdoes : are those lines included in your fork ?

@HassanCehef No.

You can't include those lines in git-flow as it's a hook triggered by git commit not a git-flow command. For more info on git hooks I suggested reading: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

@petervanderdoes thanks a lot, it worked like a charm :)

Could git-flow-init be extended to add this hook in?

@samkellett No.

As mentioned before: You can't include those lines in git-flow as it's a hook triggered by git commit not a git-flow command.

Sorry I missed your reply! When you do a git flow init, would it be possible for git flow to create (or gives the option to create) that bash script to the pre-commit file in the .git/hooks directory?

@samkellett What would be the purpose of this in git flow init? The command does not commit anything, it just creates a production and develop branch if they don't exists and add needed information to the .git/config file.

I just figured that it sets up the environment and part of that is that you should no longer commit to master, installing the hook as you create a git flow setup enforces that new distinction

@samkellett I gotcha.

Nice idea. Maybe separate in a contrib directory, like completion in git.

Yeah that could work!

Just a heads up, it won't be added in this repo. This repo hasn't been updated in 2 years.

haha, oh yeah..!

@petervanderdoes , Thanks for the script. But how can i add user wise branch push restriction ?

I'm using coco.os's interface

On 2 Nov 2016, at 11:21, Fahad Ahammed [email protected] wrote:

@petervanderdoes , Thanks for the script. But how can i add user wise branch push restriction ?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Would you like the ssh rsa key?

On 2 Nov 2016, at 11:21, Fahad Ahammed [email protected] wrote:

@petervanderdoes , Thanks for the script. But how can i add user wise branch push restriction ?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexjeffburke picture alexjeffburke  ·  24Comments

andremedeiros picture andremedeiros  ·  34Comments

nvaken picture nvaken  ·  5Comments

ripper234 picture ripper234  ·  9Comments

boryn picture boryn  ·  6Comments