Skip to content

Instantly share code, notes, and snippets.

@tigerhawkvok
Forked from joechrysler/who_is_my_mummy.sh
Last active May 27, 2021 00:08
Show Gist options
  • Save tigerhawkvok/cf546cc29cc556706dda2f373bee3324 to your computer and use it in GitHub Desktop.
Save tigerhawkvok/cf546cc29cc556706dda2f373bee3324 to your computer and use it in GitHub Desktop.
Find the nearest parent branch of the current git branch
[alias]
parentalt = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
parent = "!vbc=$(git rev-parse --abbrev-ref HEAD) && vbc_col=$(( $(git show-branch | grep '^[^\\[]*\\*' | head -1 | cut -d* -f1 | wc -c) - 1 )) && swimming_lane_start_row=$(( $(git show-branch | grep -n \"^[\\-]*$\" | cut -d: -f1) + 1 )) && git show-branch | tail -n +$swimming_lane_start_row | grep -v \"^[^\\[]*\\[$vbc\" | grep \"^.\\{$vbc_col\\}[^ ]\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"
vbc=$(git rev-parse --abbrev-ref HEAD) && vbc_col=$(( $(git show-branch | grep '^[^\[]*\*' | head -1 | cut -d* -f1 | wc -c) - 1 )) && swimming_lane_start_row=$(( $(git show-branch | grep -n "^[\-]*$" | cut -d: -f1) + 1 )) && git show-branch | tail -n +$swimming_lane_start_row | grep -v "^[^\[]*\[$vbc" | grep "^.\{$vbc_col\}[^ ]" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
#!/usr/bin/bash
# Based on https://gist.github.com/joechrysler/6073741#gistcomment-1774657
vbc=$(git rev-parse --abbrev-ref HEAD) && vbc_col=$(( $(git show-branch | grep '^[^\[]*\*' | head -1 | cut -d* -f1 | wc -c) - 1 )) && swimming_lane_start_row=$(( $(git show-branch | grep -n "^[\-]*$" | cut -d: -f1) + 1 )) && git show-branch | tail -n +$swimming_lane_start_row | grep -v "^[^\[]*\[$vbc" | grep "^.\{$vbc_col\}[^ ]" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment