5

Why can’t I merge into a bare repo? Bare repos don’t have a HEAD or a working tree. In the config file we can see bare=true.

You also can’t pull in a bare repo (because pull = fetch & merge and merge doesn't work). However, you can push to a bare repo – why? As far as I know, push also contains a merge, but in this case we can do it well.

So, the question could be “how does git merge work?”. Why does it need a HEAD? What is it doing when merging?

Chronial
  • 66,706
  • 14
  • 93
  • 99
  • 2
    Push does not do a merge in the target repo. It only does a fast-forward merge, which is not a real merge, but only moves the branch head somewhere else. – Chronial Aug 29 '13 at 01:09

1 Answers1

1

As Chronial points out, pushing does fast-forward merges or forced updates, which just moves references/branch pointers to a different commit.

In an actual non-fast-forward merge, you need a working copy in the case that you get conflicts that you need to resolve. It's been mentioned before by other Stack Overflow users; for example, see this answer (emphasis mine):

git performs all merge-y operations (real merges, cherry-picks, rebases, patch application) on the work tree. This is mentioned several times before, for example in one of the knowledgeable Jakub Narębski's answers:

There is no way that merge (or rebase) can work without touching the working directory (and index), as there can be merge conflicts that have to be resolved using working directory (and/or index).

Community
  • 1
  • 1
  • Am I right? When git do merge - first of all it look up its database. Git compare the hashes (and if they are different - it unzip the snapshots of 2 files and compare them inside). Why git need the working directory to merge two committed branches from it own database? – Naughty Leopard Aug 29 '13 at 10:52
  • Second remark and question. When we merge - what git does first? It try to compare hashes, but which of hashes? Hashes of the current branch and the merge-from-brunch. When we pull to the bare repo what git does? Git try to find hashes of the current brunch (even in bare repo we have master brunch), git look up the HEAD of the master to find last used (HEAD) committed hashes but bare repo does not have a HEAD (even the working tree). So it get the error. Is this true? please, correct me. – Naughty Leopard Aug 29 '13 at 11:21