Skip to content

Instantly share code, notes, and snippets.

@paulolorenzobasilio
Last active April 23, 2024 13:40
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulolorenzobasilio/c99165e828104bdbaffa34d8f6d4d05a to your computer and use it in GitHub Desktop.
Save paulolorenzobasilio/c99165e828104bdbaffa34d8f6d4d05a to your computer and use it in GitHub Desktop.
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