Skip to content

Instantly share code, notes, and snippets.

@intel352
Forked from joechrysler/who_is_my_mummy.sh
Last active June 26, 2021 17:06
Show Gist options
  • Save intel352/9761288 to your computer and use it in GitHub Desktop.
Save intel352/9761288 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
branch=`git rev-parse --abbrev-ref HEAD`
git show-branch | ack '\*' | ack -v "$branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
# How it works:
# 1| Display a textual history of all commits.
# 2| Ancestors of the current commit are indicated
# by a star. Filter out everything else.
# 3| Ignore all the commits in the current branch.
# 4| The first result will be the nearest ancestor branch.
# Ignore the other results.
# 5| Branch names are displayed [in brackets]. Ignore
# everything outside the brackets, and the brackets.
# 6| Sometimes the branch name will include a ~2 or ^1 to
# indicate how many commits are between the referenced
# commit and the branch tip. We don't care. Ignore them.
@tirans
Copy link

tirans commented Jun 26, 2021

Doesn't latest git support showing the parent branch in a native way?

found the following to work for me (limited testing)
git branch --create-reflog | head -n 1

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