Skip to content

Instantly share code, notes, and snippets.

@dkirrane
Created July 3, 2014 09:58
Show Gist options
  • Save dkirrane/47c6856d060e19108315 to your computer and use it in GitHub Desktop.
Save dkirrane/47c6856d060e19108315 to your computer and use it in GitHub Desktop.
Find the parent branch of the current branch
current_branch=`git rev-parse --abbrev-ref HEAD`
git show-branch -a | grep '*' | grep -v $current_branch | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
@beany-vu
Copy link

All of the branches got the error like this: cannot handle more than 25 refs

@laurentvaills
Copy link

laurentvaills commented Jun 13, 2017

I also have the warning cannot handle more than 25 refs :(

@manoharreddyporeddy
Copy link

use 2>nul for git show-branch -a

as in below
current_branch=git rev-parse --abbrev-ref HEAD
git show-branch -a 2>nul | grep '' | grep -v $current_branch | head -n1 | sed 's/.[(.)]./\1/' | sed 's/[^~]].*//'

@drkvogel
Copy link

drkvogel commented Apr 8, 2021

Just in case anyone else finds this, I wondered how 2>nul worked - it should 2>/dev/null; 2>nul creates a file called nul!

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