From ad638bb6fb1ad3926d9baeb0d9b1166f49f75e51 Mon Sep 17 00:00:00 2001 From: xpk Date: Wed, 19 Feb 2025 16:58:05 +0800 Subject: [PATCH] NEW: Script to see if commit in current branch is already in master --- sh/git-branch-clean.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 sh/git-branch-clean.sh diff --git a/sh/git-branch-clean.sh b/sh/git-branch-clean.sh new file mode 100755 index 0000000..c1cfd8b --- /dev/null +++ b/sh/git-branch-clean.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "=========================================================================" +echo "This script will check if master branch contains commit from this branch." +echo "Then suggest if the branch can be deleted" +echo "=========================================================================" +echo "" + +CURRBRANCH=$(git branch --show-current) +COMMITID=$(git rev-parse HEAD) +git switch -q master +git log | grep $COMMITID +if [ $? -eq 1 ]; then + echo "commit not found in master. You should keep $CURRBRANCH" +else + echo "commit found in master. You should delete $CURRBRANCH" + git log -n1 $COMMITID +fi +git switch -q $CURRBRANCH