github - What is the difference between git init and git init --bare?
大家讲道理
大家讲道理 2017-05-02 09:31:19
0
7
800

I haven’t found any relevant information after searching for a long time. What is the difference between git init and git init --bare?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(7)
仅有的幸福

In this article I will:

  1. Use "normal library" to refer to the GIT library created with the "git init" command;

  2. Use "bare library" to refer to the GIT library created with the "git init --bare" command;

When you create a normal library, in the working directory, in addition to the .git directory, you can also see all the source files contained in the library. You have a native library that can be browsed and modified (add, commit, delete, etc.).
When you create a bare library, there is only one .git directory in the working directory, and there is no file structure similar to the local library for you to browse and modify directly. But you can still use the git show command to browse, for example (the parameter is the SHA1 value of a certain commit):

# git show 921dc435a3acd46e48e3d1e54880da62dac18fe0

Generally speaking, a bare library is often created as a shared library for everyone to work together, and everyone can push their own local modifications into it. A common naming method is to add .git after the library name, for example:

# mkdir example.git
# cd example.git
# git init --bare .

So you have a shared library called example. On your own local machine, you can use the git remote add command to do the initial check-in:

// assume there're some initial files you want to push to the bare repo you just created,
// which are placed under example directory
# cd example
# git init
# git add *
# git commit -m "My initial commit message"
# git remote add origin git@example.com:example.git
# git push -u origin master

Everyone in the project team can clone this library, and then push their own code into this library after completing local modifications.

# git clone git@example.com:example.git
# cd example

Reference:

  1. The difference between ordinary libraries and bare libraries: http://stackoverflow.com/questions/78611...

  2. How to use a bare library: http://stackoverflow.com/questions/76324...

  3. What is GIT bare library: http://www.saintsjd.com/2011/01/what-is-...

  4. How to set up a remote shared library and collaborate as a team: http://thelucid.com/2008/12/02/git-setti...

  5. The difference between git remote add and git clone: ​​http://stackoverflow.com/questions/48555...

刘奇

The repository (bare repository) initialized with "git init –bare" only contains the ".git" directory (recording version history) and does not include a copy of the project source file. If you enter the version directory, you will find that there is only the ".git" directory and no other files. The repository only contains files that record version history.

迷茫

What the people above said is too complicated, it can be explained in 3 sentences:
1.git init creates a local warehouse (created in the project directory)
2.git init --bare creates a remote warehouse (on the server or A backup warehouse that can be created in any path other than the project directory)
Commit the project to 1 and push to 2;

阿神

bare repo has no work tree

淡淡烟草味

There is a book called "The Definitive Guide to Git" that you can read, it’s really good

曾经蜡笔没有小新

`--bare
Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory.`
http://blog.csdn.net/feizxiang3/article/details/8065506

某草草

From the perspective of usage:
git init is used for local code libraries, including all source codes in the same folder, and files related to git version control are in the .git directory;
git init --bare means to build a bare library, After executing the command, the directory will only include files related to git version control, etc., compared to all files in the .git folder above. The following directory does not include the project source code.
Generally speaking, when used as a remote backup or public repository, git init --bare should be used.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template