Skip to content

Instantly share code, notes, and snippets.

@jesstelford
Last active December 5, 2022 10:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesstelford/7762134 to your computer and use it in GitHub Desktop.
Save jesstelford/7762134 to your computer and use it in GitHub Desktop.
List the Pull Requests which have been merged into one branch but not another. Execute this from within a git directory that has it's `origin` remote set to github.
#!/bin/sh
if (( $# < 2 )) || (( $# > 3 ))
then
echo "$0 <are-in-this-branch> <are-not-in-this-branch> [<url-of-repo>]"
exit 1
fi
URLPREFIX=
if (( $# == 3 ))
then
URLPREFIX=$(echo "$3/pull/" | sed -e 's/[\/&]/\\&/g')
fi
echo "PR's which are merged in branch '$1', but not in '$2':"
# Get all the Pull Request head commits
git fetch origin "+refs/pull/*/head:refs/remotes/origin/pr/*" &>/dev/null
# Generate a list of all PR's contained in the specified branches
git branch -r --merged $1 | grep "origin/pr/*" | sort > /tmp/inthis.txt
git branch -r --merged $2 | grep "origin/pr/*" | sort > /tmp/notinthis.txt
# Clean up after getting all the PR head commits
git remote prune origin &>/dev/null
# Compare the lists of PR's contained in branches, and output result
comm -23 /tmp/inthis.txt /tmp/notinthis.txt | sed "s, origin/pr/,$URLPREFIX,g"
# Clean up temp files
rm /tmp/inthis.txt
rm /tmp/notinthis.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment