Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Created October 8, 2011 00:21
Show Gist options
  • Save mbbx6spp/1271673 to your computer and use it in GitHub Desktop.
Save mbbx6spp/1271673 to your computer and use it in GitHub Desktop.
Git hooks to enforce pull request on master workflow

Sanity checking Git Hook for pre-commit

Checks that you are trying to push to master (or other key branches) from your local repository.

Installation

Download the above raw file (edit it as you please) and place inside your Git repository under: $GITDIR/hooks/pre-commit where $GITDIR is typically .git under your project working directory. Then make sure you make it executable: chmod +x .git/hooks/pre-commit

#!/usr/bin/env ruby
$restricted_branches = ['master', 'staging', 'qa', 'production']
# Prevents local committing to master branch.
# Will no effect pull requests on GitHub to the restricted branches,
# nor will it stop receives from remotes.
def verify_branch_name
branch_name = %x[git name-rev --name-only HEAD].chomp
if $restricted_branches.include?(branch_name)
abort('ERROR: Cannot commit to the #{branch_name} branch')
end
end
verify_branch_name
@smit-darji
Copy link

cvse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment