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?
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).
来源:https://stackoverflow.com/questions/18498241/why-can-t-you-merge-in-a-bare-git-repo