Skip to content

Instantly share code, notes, and snippets.

@we4tech
Created November 9, 2015 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/683135493b1fe9417a9d to your computer and use it in GitHub Desktop.
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
#!/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