Skip to content

Instantly share code, notes, and snippets.

@un1ko85
Created May 9, 2013 06:52
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 un1ko85/5545989 to your computer and use it in GitHub Desktop.
Save un1ko85/5545989 to your computer and use it in GitHub Desktop.
Git: extract branch name in post update hook But if branch was deleted (for example by git push origin :branch-name), you will receive errors from this command, so I think it’s safer to use another method: As post-update hook receives branch’s path as first parameter (something like refs/heads/branch-name), you can extract the branch name using …
branch=$(git rev-parse --symbolic --abbrev-ref $1)
branch=$(echo $1 | awk -F'/' '{print $3}')
if [ ! -f $1 ]; then
echo "Branch $branch was deleted! Do something then.."
else
echo "Branch $branch was updated! Do something then.."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment