What's the -practical- difference between a Bare and non-Bare repository?

后端 未结 11 2286
南方客
南方客 2020-11-22 16:16

I\'ve been reading about the bare and non-bare / default repositores in Git. I haven\'t been able to understand quite well (theoretically) about the differences between them

11条回答
  •  清歌不尽
    2020-11-22 16:37

    Another difference between a bare and non-bare repository is that a bare repository does not have a default remote origin repository:

    ~/Projects$ git clone --bare test bare
    Initialized empty Git repository in /home/derek/Projects/bare/
    ~/Projects$ cd bare
    ~/Projects/bare$ git branch -a
    * master
    ~/Projects/bare$ cd ..
    ~/Projects$ git clone test non-bare
    Initialized empty Git repository in /home/derek/Projects/non-bare/.git/
    ~/Projects$ cd non-bare
    ~/Projects/non-bare$ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    

    From the manual page for git clone --bare:

    Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.

    Presumably, when it creates a bare repository, Git assumes that the bare repository will serve as the origin repository for several remote users, so it does not create the default remote origin. What this means is that basic git pull and git push operations won't work since Git assumes that without a workspace, you don't intend to commit any changes to the bare repository:

    ~/Projects/bare$ git push
    fatal: No destination configured to push to.
    ~/Projects/bare$ git pull
    fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
    ~/Projects/bare$ 
    

提交回复
热议问题