Bare git vs .git/ - purpose of config.bare

帅比萌擦擦* 提交于 2020-01-17 13:05:08

问题


Background:

I've created a bare repo

cd ~  
git init --bare GitDrive  

The idea was to use this as the git dir for google drive

cd "Google Drive"  
echo "gitdir: ../GitDrive  

But git didn't like this until I removed bare = true from .git/config

This got me thinking about the purpose of having a configuration setting whether a repo is bare or not.
Reading git-config it appears to be used to avoid having to guess whether a repo is bare or not.

I know you can't checkout in a bare repo but you can't checkout in a repo/.git/ either regardless of the config.bare setting.

In what situations can't git determine whether a repo is bare or not?

What is the technical term for the directory containing the files config/info/hooks/index...?
Being repo/ for a bare repo and repo/.git/ otherwise.

What is the technical difference between a repo created using git init --bare and pulling the .git directory out of a live repo?


回答1:


A bare repository is not associated with any working directory at all. Its purpose is to accept pushes from other repositories. A non-bare repository has a working directory, which is the parent directory of the .git folder. Although non-bare repositories can technically be pushed to, it is not advisable because if you are pushing to the current branch of the non-bare repository, it can cause issues with the working directory and index since they might not be merged correctly.

A bare repository can have a current branch, but when you check out branches there is no effect except to the HEAD file. The purpose of this is to browse using Git commands. No direct view of the file structure is available.




回答2:


Your question is not clear; if the goal is to put the files you have on the directory Google Drive in a git repository that is located outside the Google Drive directory then the solution is very simple:

cd "Google Drive"
git init --separate-git-dir ../GitDrive

Make sure the directory ../GitDrive does not already exists or it is empty.

This way git will create the repository in directory ../GitDrive instead of ./.git (inside the current directory). It will create, however, a file named .git in the working tree (the "Google Drive" directory) that contains the path of the repository (the complete path to ../GitDrive).

You can run your git commands both in Google Drive and in GitDrive, they will work (the repository also knows where the working tree is). But you have no real reason to mess around with files in the repository. Do your work in the working tree (directory Google Drive), as usual.



来源:https://stackoverflow.com/questions/27944745/bare-git-vs-git-purpose-of-config-bare

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!