Skip to content

Instantly share code, notes, and snippets.

@spazm
Created June 24, 2015 21:01
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 spazm/877133497646fc7716c4 to your computer and use it in GitHub Desktop.
Save spazm/877133497646fc7716c4 to your computer and use it in GitHub Desktop.
.git/hooks/post-checkout for logging branch changes. Will mine this to see what sort of frecency map would be useful for finding "hot" branches
#!/bin/sh
previous_head_ref=$1
new_head_ref=$2
is_branch_checkout=$3
if [[ "$previous_head_ref" != "$new_head_ref" ]] && [[ "$is_branch_checkout" == 1 ]]; then
branch=$(git rev-parse --abbrev-ref HEAD)
#if [[ "develop" != "$branch" ]]; then
path="$(dirname "$0")/.."
logfile="$path/x_branch_log"
ts=$(date +%s)
echo "$branch|1|$ts" >> $logfile
#fi
fi
@spazm
Copy link
Author

spazm commented Jun 24, 2015

post-checkout hook provides the raw SHA1 for previous_head and current_head. At first I tried to turn those back into branch names, but that was error-prone (could be the tip of multiple branches). But then realized I could get the branch info from the new branch via rev-parse, since post-checkout runs after the checkout is complete (by definition).

git rev-parse --abbrev-ref HEAD is the preferred way to get the current branch using git plumbing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment