Find git parent branch
This is a situation I very infrequently find myself in, but when I do find myself here, I always scramble around the internet and suffer through a lot of just and other typical Stack Overflow crap.
This is a little snippet to run in your terminal and it will output a load of useless guff, but importantly, right at the end, you'll see the current branch's parent branch:
git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//'
I'm not 100% sure how it works, but it does work by cleaning up a big old list of data with regular expressions.
This note is mainly for me so I don't have to go through the trauma of finding this snippet again!
Hi 👋
I’m Andy, a freelance web designer
I’m not currently booking new projects, but you can support my work by buying “Every Layout”.