From 5294df37a0c3bbbc4c1fd0baf3a9335c3802b108 Mon Sep 17 00:00:00 2001 From: smckown Date: Wed, 9 Dec 2009 18:09:35 +0000 Subject: [PATCH] Add a command to create an empty git branch. I find that I use this all the time. --- git-empty-branch | 26 ++++++++++++++++++++++++++ git-empty-branch.1 | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 git-empty-branch create mode 100644 git-empty-branch.1 diff --git a/git-empty-branch b/git-empty-branch new file mode 100755 index 0000000..75e90ff --- /dev/null +++ b/git-empty-branch @@ -0,0 +1,26 @@ +#!/bin/sh +# git-empty-branch [branch] + +if [ $# -eq 1 ]; then + branch=$1 +else + echo "Usage: $0 [branch]" >&2 + exit 1 +fi + +if [ -n "$(git show-ref --heads $branch)" ]; then + echo "branch already exists" >&2 + exit 1 +fi + +git symbolic-ref HEAD refs/heads/$branch && \ + rm .git/index && git clean -fdx && \ + echo "Now on empty branch $branch" || \ + fail +exit 0 + +fail() +{ + echo "Branch failure. You may need to git reset --hard" >&2 + exit 1 +} diff --git a/git-empty-branch.1 b/git-empty-branch.1 new file mode 100644 index 0000000..a78daec --- /dev/null +++ b/git-empty-branch.1 @@ -0,0 +1,22 @@ +.\" +.TH "git-empty-branch" +.SH NAME +git-empty-branch \- create a new empty branch in the local repository + +.SH SYNOPSIS +\fBgit-empty-branch\fR [\fIBRANCH\fR] + +.SH "DESCRIPTION" + +.PP +\fBgit-empty-branch\fR creates a new empty branch in the local repository. +\fIBRANCH\fR must not already exist. + +.SH "OPTIONS" + +.TP +\fIBRANCH\fR +The name to assign the new empty branch. + +.SH "SEE ALSO" +git-branch(1) -- 2.39.2