threads / discuss / 3834

Re: How to create independent branches

Subject: Re: How to create independent branches

## tl;dr

One message between Apr 8, 2006 and Apr 8, 2006.

replies: 0people: 1as markdown or json

colin@horizon.com· Apr 8, 2006, 23:15 UTC · lore
  669  git-symbolic-ref HEAD refs/heads/slave
  670  echo "ref: refs/heads/master" > .git/HEAD
  671  git-symbolic-ref HEAD refs/heads/slave
  672  git add bar
Show 12 quoted lines
> Another question. I'd like to create a totaly independent branch (like
> the "todo" branch in git). Is there a more user friendly way than doing
> 
> git-checkout -b todo
> rm .git/refs/heads/todo
> rm .git/index
> rm <all_files_in_your_workdir>
> 
> ... hack hack hack ...
> git-commit -a
> 
> I looked all over the docs, but can't find anything obvious.

If I undertstand, you basically want to create a second initial commit, so you have two trees in your repository.

Well, an initial commit is just a commit object with no parents.
Try:
- Set up the workdir the way you want.  You have to git-add
  any newly added files, but git-update-index (called by
  git-commit -a) will remove from the index any files
  removed from the working directory, so you don't have to
  worry about those.
- Make sure refs/heads/todo doesn't exist
- "git-symbolic-ref HEAD refs/heads/todo"
  This makes HEAD a symlink (well, symref) to refs/heads/todo,
  which doesn't exist.
- git-commit -a
  Since the HEAD link doesn't exist, this does an initial
  commit.

It's not supremely user friendly, because multiple initial commits can lead to problems down the road trying to merge, so you'd better know what you're doing.

Another option is to just set up a second working directory, with a shared object store, and do the checkin from there. You can have the .git/refs directories shared (via a symlink) or not. If they're not shared, you can later make them shared by copying over the relevant refs.

Oh, yes, note that if you fat-finger the "git-symbolic-ref HEAD" command, any attempts to fix it will complain "not a git repository". That's because a reference to refs/heads/ in HEAD is how git identifies a repository. "echo ref: refs/heads/master > .git/HEAD" will fix it.

← back to recent threads