From: W. Trevor King Date: Wed, 11 May 2011 16:52:20 +0000 (-0400) Subject: Added git-unmerged-branches.sh X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ad063b8ef605dc0e046cd569d4d6faaceef1ee95;p=blog.git Added git-unmerged-branches.sh --- diff --git a/posts/Git.mdwn b/posts/Git.mdwn index 8a6316a..9be0e13 100644 --- a/posts/Git.mdwn +++ b/posts/Git.mdwn @@ -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 index 0000000..2584615 --- /dev/null +++ b/posts/Git/git-unmerged-branches.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Copyright (C) 2011, William Trevor King +# +# 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 . +# +# 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