Added git-unmerged-branches.sh
authorW. Trevor King <wking@drexel.edu>
Wed, 11 May 2011 16:52:20 +0000 (12:52 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 11 May 2011 16:52:20 +0000 (12:52 -0400)
posts/Git.mdwn
posts/Git/git-unmerged-branches.sh [new file with mode: 0755]

index 8a6316a2647d76b8cd9d3a083e3029edae44d933..9be0e1364f407d779e4faa7d63e82917b21a8e66 100644 (file)
@@ -20,6 +20,11 @@ There are many tools which use version control systems as storage
 backends for various utilities.  For example, [ikiwiki][] is a
 VCS-based wiki, and [[Bugs Everywhere|BE]] is a VCS-based bug tracker.
 
+I've also written up a few scripts to automate common Git tasks:
+
+* [[git-unmerged-branches.sh]] lists unmerged branches
+
+
 [Git]: http://git.or.cz/
 [DVCS]: http://en.wikipedia.org/wiki/Distributed_Version_Control_System
 [VCS]: http://en.wikipedia.org/wiki/Revision_control
diff --git a/posts/Git/git-unmerged-branches.sh b/posts/Git/git-unmerged-branches.sh
new file mode 100755 (executable)
index 0000000..2584615
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Copyright (C) 2011, William Trevor King <wking@drexel.edu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# usage: git-unmerged-branches.sh
+#
+# List branches with commits not merged into the current branch.
+#
+# Inspired by jcromartie's https://gist.github.com/892979/
+
+BRANCH_LIST_OPTS="-a"  # compare against all branches
+#BRANCH_LIST_OPTS="-r"  # only compare against remote branches
+
+#CURRENT_BRANCH=$(git branch | grep '^\*' | sed 's/\* *//');
+BRANCHES=$(git branch $BRANCH_LIST_OPTS | grep -v '^\*\| -> ')
+
+for BRANCH in $BRANCHES; do
+       CONTAINS=$(git branch --contains "$BRANCH" | grep '^\*')
+  if [ -z "$CONTAINS" ]; then
+               echo $BRANCH
+       fi
+done