Re: creating a new branch without an ancestor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, February 4, 2010 20:19, Michael Wookey wrote:
> Maybe I'm missing something from reading the docs, but I couldn't see
> how to create a new branch in an existing repo that has no ancestor. I
> would like to do something like what git.git does with some of the
> other ancillary branches like "man", "html", and "todo".
>
> I was hoping to do something like "git branch --no-ancestor
> new-branch-name" but didn't see anything in the documentation that
> describes the necessary branch options.
>
> Or, am I looking in the wrong place?

I do this all the time for various reasons, so I made myself a
"git-emptybranch" command and stuck it in my path. Besides the error
checking, this just creates a new ref and clears the index so you can
start from a clean slate. No actual files are deleted from the work-tree.

$ cat ~/bin/git-emptybranch
#!/bin/sh
if [ $# -ne 1 ]; then
  2<&1
  echo "usage: git emptybranch <new_branch>"
  exit 1
fi

if ! git check-ref-format refs/heads/"$1"; then
  2<&1
  echo "fatal: '$1' is not a valid branch name."
  exit 1
fi

git symbolic-ref -m "git emptybranch $1" HEAD refs/heads/"$1"
git rm --cached -r -q --ignore-unmatch -- '*'

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]