git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to create independent branches

From
Ccolin@horizon.com <colin@horizon.com>
Date
Apr 8, 2006, 23:15 UTC
Message-ID
<20060408231520.27044.qmail@science.horizon.com>
  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.

Message 1 of 1 in “Re: How to create independent branches”
  1. colin@horizon.comApr 8, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.