Tide Lake Tide Lake - 4 months ago 28
Git Question

Git hook to get prior branch name

I'm working on

and having trouble either sourcing/exporting the branch name, or getting the prior branch name. I want to restart the server when switching to or from

I couldn't figure out how to source the env var in bash, so I tried using git to get the prior branch, but the closest I got was
git checkout -
git checkout @{-1}
, tho I'm not sure simply how to retrieve the prior branch name without the call to checkout.

Should I be using Git env vars instead of shell?

Current file just restarts the server on each checkout


touch tmp/restart.txt
echo " *** restarting puma-dev"

current_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [ "$current_branch" = "s3" ]
echo " *** please don't upload any files"


You should be able to use this line to grab the previous branch name:

git rev-parse --abbrev-ref @{-1}

and to get the current branch name:

git rev-parse --abbrev-ref HEAD