Is there a way to trigger a hook after a new branch has been checked out in Git?
The post-checkout
hook receives three parameters:
0
) or branch checkout (1
)You can use the fact that a branch created from the current HEAD will have the same value for parameters 1 and 2.
cat > .git/hooks/post-checkout <<"EOF"
if [ "$3" == "0" ]; then exit; fi
if [ "$1" == "$2" ]; then
echo "New branch created. (Probably)."
fi
EOF
chmod u+x .git/hooks/post-checkout
Limitations: