Skip to content

Instantly share code, notes, and snippets.

@paulolorenzobasilio
Last active August 22, 2022 18:07
Embed
What would you like to do?
Check if source branch has been already merged into destination branch
#!/usr/bin/env bash
#
# Check if source branch has been already merged into destination branch
# https://stackoverflow.com/questions/226976/how-can-i-know-if-a-branch-has-been-already-merged-into-master
#
git_is_merged () {
merge_destination_branch=$1
merge_source_branch=$2
merge_base=$(git merge-base $merge_destination_branch $merge_source_branch)
merge_source_current_commit=$(git rev-parse $merge_source_branch)
if [[ $merge_base = $merge_source_current_commit ]]
then
echo $merge_source_branch is merged into $merge_destination_branch
return 0
else
echo $merge_source_branch is not merged into $merge_destination_branch
return 1
fi
}
git_is_merged $1 $2
@brnpimentel
Copy link

Great to use in Github Actions

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