tags:

views:

186

answers:

2

Hello.

I've faced strange problem with my git repo. In process of cloning it looses all it's heads except master. Isn't head is just a file-reference to the commit id? Or it should be registered somewhere else to be cloned?

It looks exactly as William Pursell described:

 cd a
 $ git branch
   master
   * test
 $ cd ..
 $ git clone a b
 Initialized empty Git repository in /private/tmp/b/.git/
 $ cd b
 $ git branch
   * master
+3  A: 

Perhaps you haven't pushed all of your branches to your remote repository. Cloning a remote repository should automatically include all remote branches.

Note that remote branches do not automatically become local branches. You can use the git branch -a command to see all the branches you have. Example:

$ git branch -a
* master
  remotes/origin/next
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

With that, we can turn the "next" remote branch into a local one with git checkout -b and specify the remote branch as a starting point:

$ git co -b next origin/next
Branch next set up to track remote branch next from origin.
Switched to a new branch 'next'

And now you're all set for working on "next".

Christian Vest Hansen
A: 

I think that there's something wrong with both your and William Pursell's git install. Please consider logging a bug report.

What git clone should do, is to copy the remote heads into refs/remotes/origin/* and then check out a new branch with the same name and state as what's checked out as the remote's HEAD.

In your case, git branch shows that test is checked out on the source repostiory, so git clone should create a test branch in the destination repository based on the remote test branch.

Here's what I get.

$ cd a
$ git branch
  master
* test
$ cd ..
$ git clone a b
Initialized empty Git repository in /home/charles/src/gittest/b/.git/
$ cd b
$ git branch
* test
$ git branch -a
* test
  remotes/origin/HEAD -> origin/test
  remotes/origin/master
  remotes/origin/test
$ git config branch.test.remote
origin
$ git config branch.test.merge
refs/heads/test
Charles Bailey