# Bare Git, libgit2sharp question

**URL:** https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319
**Category:** Non-Tech
**Tags:** net, oxygene
**Created:** [May 7, 2018, 12:03pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319 "2018-05-07T12:03:07Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [May 7, 2018, 12:03pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/1 "2018-05-07T12:03:08Z")

</div>

Does anybody have experience with libgit2sharp and/or bare git repos?

I tried to create a git repo to track some files but always get a **detached HEAD** and I cannot figure out what I’m doing wrong.  
See: [https://stackoverflow.com/questions/50212184/commit-to-bare-git-using-libgit2sharp](https://stackoverflow.com/questions/50212184/commit-to-bare-git-using-libgit2sharp)

Any ideas?

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 7, 2018, 12:38pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/2 "2018-05-07T12:38:35Z")

</div>

I thought that a bare git repository by definition is just a copy of the repository (so you don’t have a working copy) and thus not a branch you’re working on.

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [May 7, 2018, 12:42pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/3 "2018-05-07T12:42:44Z")

</div>

Yes, there is no working copy. But when I now clone the bare git, it should produce a proper git with the working copy (it creates the working copy by going through the commits).  
When I clone my bare git, I get a warning regarding detached HEAD.

I also did create a normal git using git commands (not libgit2sharp) and created a bare repo out of it. The difference between my bare repo and the one I created via git commands was that my repo was not connected to the master branch.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 7, 2018, 12:49pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/4 "2018-05-07T12:49:57Z")

</div>

That’s because you checkout a commit, not a branch. Commits are detached, branches are not. If you want a specific branch:  
git checkout -b mybranch abcdef

However when you push a commit on top of non-top revision it will fail (without a git pull first)

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [May 7, 2018, 12:52pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/5 "2018-05-07T12:52:52Z")

</div>

maybe I do not understand it properly, but it appears like my commit are not assigned to any branch.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 7, 2018, 12:55pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/6 "2018-05-07T12:55:14Z")

</div>

Commits usually aren’t, since a specific commit can be in multiple branches. You should checkout a branch, not a commit. If your purpose is to just read from a past commit, then the detached HEAD is not a problem.

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [May 7, 2018, 1:05pm UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/7 "2018-05-07T13:05:24Z")

</div>

I see that I can recreate the complete source from the commits, so it’s not necessarily a problem.

But, in my repo, the commits are not assigned to any branch, I cannot clone a branch (or checkout). I can only clone the complete thing, there no branches or so. it’s like I lose what the head originally pointed to when the repo got created.

It looks different than when I do it using normal git and crate a bare git out of it.

gitk shows no branches, just the linked commits.

Do I need to create the master branch? Isn’t it there by default? (As the Tip is empty and the branches, too)

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 8, 2018, 4:17am UTC](https://talk.remobjects.com/t/bare-git-libgit2sharp-question/16319/8 "2018-05-08T04:17:32Z")

</div>

The real question is: do you really need a branch? If you’re not going to change anything, a detached commit is perfectly fine.
