Skip to content

Instantly share code, notes, and snippets.

@r-k-b
Created December 2, 2020 02:54
Show Gist options
  • Save r-k-b/6e5d4a54845c7651dad5933f1ecb635f to your computer and use it in GitHub Desktop.
Save r-k-b/6e5d4a54845c7651dad5933f1ecb635f to your computer and use it in GitHub Desktop.
# quick way to see if the given local branch has already been merged (or
# rebased) into the "main" branch
#
# Usage:
#    isMerged branch-i-want-to-check
#
# Defaults to the current branch if none is specified.
# Assumes the remote is named `origin`.
function isMerged() {
    echo "If a line starts with +, it's not in the main branch."
    echo "If a line starts with =, it's already in the main branch."
    checking=${1:-$(git symbolic-ref --short HEAD)}
    main="$(git remote show origin | grep "HEAD branch" | sed 's/.*: //')"
    cmd="git log --oneline --cherry origin/$main...$checking"
    echo "$cmd" && $cmd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment