The difference between git init and git init–bare

Source: Internet
Author: User
The difference between git init and git init–bare

Using the command "Git init--bare" (Bare Chinese means: bare, bare) the initialized repository (known as bare repository) only generates a class of files: Files that are used to record the repository history of the. Git directory, but not the actual project source files So the repository cannot be called the working directory (working tree); If you go into the version directory, you will find only files in the. git directory, and no other files; that is, the files in this repository are files in the. git directory, Put the files that were originally in the. git directory under the root of the repository; in other words, when the--bare option is not used, the. git directory is generated and the version history files under it are stored in the. git directory, while the--bare option is used. The. Git directory is no longer generated, but only the version history files under the. Git directory are generated, and these version history files are no longer stored under the. git directory, but are stored directly under the repository's root directory.

Repository users initialized with "Git init" can also perform all GIT operations in that directory. However, other users will be prone to conflict when updating push comes up.

For example, a user performs a git operation under the directory (called a remote repository) and has two branches (master and B1), currently under the Master branch. Another user wanted to submit an update to the master branch of the remote repository that he had in the local repository (known as the Local repository), and he took it for granted.

Git push Origin Master:master

Then came

Because the user of the remote repository is working on the master branch and you are submitting the update to the master branch, there is a mistake.

However, if it is possible to commit to an idle branch in the remote repository, such as

Git push origin master:b1 can still be successful.

The workaround is to use the "Git Init–bare" method to create a so-called bare repository, which is called a bare repository because the repository only saves the version information that Git history commits, and does not allow the user to do all kinds of git operations on it, and if you want to work hard, you will only get the following error ("This Operation must is run in a work tree ")

This is why it is best to initialize the remote repository into a bare warehouse.


Transferred from: http://blog.csdn.net/feizxiang3/article/details/8065506

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.