Created
November 9, 2015 12:42
-
-
Save we4tech/683135493b1fe9417a9d to your computer and use it in GitHub Desktop.
GIT Pre push script to prevent from accidental force push to master branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Make sure you have 'colorize' gem installed already. | |
require 'colorize' | |
current_branch = `git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,'` | |
push_cmd = `ps -ocommand | grep "git push"` | |
if current_branch =~ /\/master/ && push_cmd =~ /(\-f|force|delete)/ | |
puts '*********************************************'.colorize(:red) | |
puts '** You can not force push to MASTER **'.colorize(:red) | |
puts '*********************************************'.colorize(:red) | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment