I want to use the below on a windows 10 machine to know the nearest parent of a git branch.
But I am not able to run it, please help.
#!/usr/bin/env zsh
git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| 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.
I have taken the script form https://gist.github.com/joechrysler/6073741#file-who_is_my_mummy-sh
FYI, I have very limited Linux knowledge.
I don't want to use WSL or Cygwin
I have got the grep.exe and sed.exe and other exes from Linux utils.
Even If I run the below command in the windows command prompt, I get the below error
git show-branch -a | grep '\*'
Error:
warning: ignoring origin/branchname; cannot handle more than 26 refs
Edit:
I saved the above command in a file parent.sh and When I run it in Git Bash, It gives the below error. Am I missing anything here?