Skip to content

Instantly share code, notes, and snippets.

@mezis
Created February 9, 2012 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mezis/1780617 to your computer and use it in GitHub Desktop.
Save mezis/1780617 to your computer and use it in GitHub Desktop.
Close a feature branch - removing it from local and remote
#!/bin/bash
#
# Close a feature branch - removing it from local and remote.
#
die() {
echo "$@" ; exit 1
}
head=$(git symbolic-ref HEAD 2> /dev/null || git log -1 --format=%h)
current_branch=${head#refs/heads/}
branch="$1"
: ${branch:-$head}
echo "Closing feature branch $branch"
if [ "$branch" = "$current_branch" ] ; then
git checkout master || die
fi
git branch -d "$branch" || die
git push origin ":$branch" || die
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment