Git empty branch bash script

Posted by on August 17, 2010 at 1:48 pm.

Sometimes I create empty branchs while designing some webs and I got tired of making all the thing manually; so, some time ago I wrote a little bash script that may work for any of you to do this task. It takes the first parameter as the name of the new branch to be created, here’s the code:

#!/bin/sh
# creating a git empty branch
# it takes as arg the name for the new branch

git-symbolic-ref HEAD refs/heads/$1
rm .git/index
git clean -fdx
git commit --allow-empty -m "Initial empty branch commit"

Hope it works for someone.

  • Marcandre Lureau

    http://gitlog.wordpress.com/2010/07/22/git-1-7-2/

    Isn’t that the same as “git checkout –orphan newbranch” with 1.7.2?

  • http://www.joseluisrivas.net Jose Luis Rivas

    Thanks! That’s just great :-) I didn’t knew because on debian/SID the last git is 1.7.1 so couldn’t test it. As soon as 1.7.2 reach debian/sid I will update this post.

  • M

    Every time I use git it surprises me a in a new and ugly way…