-
-
Save psema4/22a5bd624dea5d353531 to your computer and use it in GitHub Desktop.
Determine "parent" of the active git branch (Ubuntu)
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
#!/usr/bin/env bash | |
# via http://stackoverflow.com/a/17843908/773209 | |
# | |
# Ubuntu variant | |
# | |
# if ack-grep isn't found: | |
# $ sudo apt-get install ack-grep | |
branch=`git rev-parse --abbrev-ref HEAD` | |
git show-branch 2>&1 | ack-grep '\*' | ack-grep -v "$branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//' | grep -v 'more than 25' | |
# How it works: | |
# 1| Get a textual history of all commits. | |
# 1A| Redirect git's STDERR to STDOUT. | |
# 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. | |
# 7| Strip excessive refs warnings (originally sent to | |
# STDERR) before rendering the output. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: If you need this script, it's worth reading the StackOverflow thread ;)