0

When I tried to delete a branch in a bare repo, I was told that I can't because I'm "currently on it". A bit surprising, as I expected not to be on any branch in a bare repo.

Which branch should be active in a bare repo used as the central repository to cause minimal side-effects? Is the active branch merely a vestige from non-bare repos?

Before bare repos I had a "dummy" branch checked out, now I'm wondering if I should still have a "dummy" branch active on my central bare repo.

Roman Starkov
  • 52,420
  • 33
  • 225
  • 300

3 Answers3

4

Bare repos has a symbolic HEAD reference which points to a default branch, usually master. Whichever branch origin/HEAD points to is the default branch that's checked out for any clones of that bare repo. See How does origin/HEAD get set?.

Also, from the official Linux kernel docs for git-remote:

set-head

Sets or deletes the default branch (i.e. the target of the symbolic-ref refs/remotes/<name>/HEAD) for the named remote. Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch.

Community
  • 1
  • 1
1

I presume you mean the HEAD branch on the bare repo? This just gives a clue to new clones which branch is considered the default to checkout when cloning for the first time. It's fairly inconsequential.

Gary Fixler
  • 4,762
  • 1
  • 17
  • 37
  • @romkyns that's not the error message I get when trying to delete `master` in a bare repo, can you show us your full delete command and error message please? What version of Git are you using? –  Mar 31 '14 at 09:34
  • @Cupcake - did you mean to reply to me here? – Gary Fixler Mar 31 '14 at 09:37
  • romkyns actually had another comment here earlier, but it looks like he deleted it. –  Mar 31 '14 at 09:40
  • That's right. There was no mention of "active" anywhere, my fault. – Roman Starkov Mar 31 '14 at 09:48
1

To cite the git clone manual page:

--branch <name>
-b <name>

Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.

So basically you keep HEAD in the remote repo pointing to whatever branch you'd like your clones to make the default one. No need to keep a dummy branch.

kostix
  • 43,267
  • 10
  • 69
  • 137