create a repository with workspaces
When you start a new project, you first create and initialize the code base. If it is in the working directory of this machine, then:
$ git init
It's enough. If the repository you want to initialize is not in the current directory, you need to specify the directory where the repository is located for the git init command:
$ git init hello
After executing the command, a directory named. Git is created in the current directory or under the directory you specified, which is the repository.
Repositories with workspaces are used primarily for daily work. It works by committing the code to the local repository and then pushing it to the repository on the server through the local library.
Create a bare version library
With respect to the repository with workspaces, the bare repository exists primarily on the server as a centralized version repository. Because no one will modify the code on the server and commit it, this type of repository does not require a workspace. Of course, the way it is created is slightly different from the version library with the workspace.
$ git init--bare
Option--bare is used to create a bare repository, open the current directory and you will see git creating some directories and files.
For easy viewing, the directory name of the bare repository is usually added to the. git suffix:
$ git init–bare hello.git
This is a lot clearer, both in terms of appearance and use.
initializing a bare version library with an existing library
Because the bare repository does not have a workspace, it is not possible to submit the code directly to the bare version library. The common practice is to clone the bare repository, commit it in the local library, and then push it to the bare repository.
So how do you initialize a bare repository with an existing library?
All roads lead to Rome, and we can achieve it in different ways.
Method 1, clone a bare repository from an existing library:
$ git clone–bare Hello Hellobare.git
Use the git log command to view the repository Hellobare.git, whose history and repository Hello are the same.
Method 2, push the existing library to the bare repository:
$ git push–all hellobare2.git
Using the git log command to view the Hellobare2.git library, its history and repository Hello are the same.
Git Initialize Repository