Created
October 6, 2023 15:48
-
-
Save evilbuck/5079af0b60653e9fb16fff47d2c6ca2d to your computer and use it in GitHub Desktop.
Git: Find the nearest ancestor branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Another way to phrase the question is | |
| # "What is the nearest commit that resides on a branch other than the current branch, | |
| # and which branch is that?" | |
| git show-branch -a \ | |
| | grep '\*' \ | |
| | grep -v `git rev-parse --abbrev-ref HEAD` \ | |
| | head -n1 \ | |
| | sed 's/[^\[]*//' \ | |
| | awk 'match($0, /\[[a-zA-Z0-9\/.-]+\]/) { print substr( $0, RSTART+1, RLENGTH-2 )}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment