Useful snippets

    prepush / git hooks

    To activate pre-push, rename .git/hooks/pre-push.sample to .git/hooks/pre-push


    Example script:

    GREEN='\033[0;32m'
    RED='\033[1;91m'
    RESET='\033[0m'
    
    branch_name="$(git branch --show-current)"
    allowed_branch_name="my-branch"
    
    if [ "$branch_name" != "$allowed_branch_name" ]; then
      echo "Current branch: ${RED}${branch_name}${RESET}"
      echo "Allowed branch: ${GREEN}${allowed_branch_name}${RESET}" 
      echo
      echo "You can't push directly to this branch."
      exit 1
    fi

    Insert the current branch into the top of the pre-push file

    sed -i "" "s&An example&$(git branch --show-current)\n# An example&" .git/hooks/pre-push 

    Replace "An example" with current branch \n # An example

    Copy current branch to Mac clipboard

    echo $(git branch --show-current) | pbcopy 

    From vim:

    :!echo $(git branch --show-current) | pbcopy