Skip to content

Instantly share code, notes, and snippets.

@hbeni
Created April 27, 2021 06:28
Show Gist options
  • Save hbeni/16ffe4bfdfc31ce7d1fbe850e4510c3f to your computer and use it in GitHub Desktop.
Save hbeni/16ffe4bfdfc31ce7d1fbe850e4510c3f to your computer and use it in GitHub Desktop.
GIT command: show branches the current branch contains
#!/bin/bash
#
# Show which branches the current branch contains
#
current_branch=$(git branch |grep ^* |sed 's/^[*]*\s*//')
branches_file=$(mktemp)
git branch |sed 's/^[*]*\s*//' > $branches_file
while read branch; do
branch_file=$(mktemp)
git branch --contains $branch > $branch_file
grep -q "$current_branch" $branch_file
[ $? -eq 0 ] && echo $branch
rm $branch_file
done < $branches_file
rm $branches_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment