From 5a10c0c0963b9b3e6bec2f84c6187e84b8b3dc6d Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Mon, 15 Jun 2020 12:31:52 -0400 Subject: [PATCH] Get the name of the main branch from remote --- bin/git-merge-branch | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/git-merge-branch b/bin/git-merge-branch index c8f8d9d..e82e698 100755 --- a/bin/git-merge-branch +++ b/bin/git-merge-branch @@ -1,13 +1,19 @@ #!/bin/sh -main_branch="master" - -if [ $# -gt 0 ]; then - main_branch=$1 -fi - set -e +if git symbolic-ref --short refs/remotes/origin/HEAD >/dev/null; then + main_branch="$(git symbolic-ref --short refs/remotes/origin/HEAD | sed 's@^origin/@@')" "$@" +else + echo "You don't have a primary branch reference set for your origin remote. + Use: + git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/{name_of_your_primary_branch} + + to set the reference and then try merging again." + + exit +fi + git fetch origin line_count=$(git diff origin/$main_branch..$main_branch | wc -l)