at kaneshin
Home Talks Posts Links

23 Mar 2015
Push to master

Git is good for us to manage version of source files.

Sometimes, someone who is member of project delete or overwrite forcely master branch by mistaken.

I wouldn’t like to restore branch for it.

So, our project is adopting “pre-push” script to hook when git-push.

“pre-push” is contained script below;

#!/bin/bash

while read local_ref local_sha1 remote_ref remote_sha1
do
  if [[ "${remote_ref##refs/heads/}" == "master" ]]; then
    res=""
    while [[ "${res}" != "Y" ]] && [[ "${res}" != "N" ]]; do
      echo -n "Do you want to push the master branch to remote [y/N]? "
      read -s -n 1 res < /dev/tty
      if [[ "$res" == "" ]]; then
          res="N"
      fi
      res=`echo "${res}" | tr '[a-z]' '[A-Z]'`
    done
    echo ""
    if [[ "${res}" == "N" ]]; then
        exit 1
    fi
  fi
done

Use this script if you bother mistaken git-push from others.


Til next time,
kaneshin at 02:10