Git creates a repository
In this chapter we will introduce how to create a Git warehouse.
You can use an existing directory as a Git repository.
git init
Git uses the git init command to initialize a Git warehouse. Many Git commands need to be run in the Git warehouse, so git init is the first command to use Git.
After executing the git init command, the Git repository will generate a .git directory, which contains all metadata of the resources. Other project directories remain unchanged (unlike SVN A .svn directory will be generated in each subdirectory, and Git only generates a .git directory in the root directory of the warehouse).
Usage
Use the current directory as the Git repository, we just need to initialize it.
git init
After this command is executed, a .git directory will be generated in the current directory.
Use the directory we specified as the Git repository.
git init newrepo
After initialization, a directory named .git will appear in the newrepo directory. All data and resources required by Git are stored in this directory.
If there are several files in the current directory that you want to include in version control, you need to first use the git add command to tell Git to start tracking these files, and then submit:
$ git add *.c $ git add README $ git commit -m '初始化项目版本'
The above command will Submit the file ending with .c and the README file to the warehouse.
git clone
We use git clone to copy a project from an existing Git repository (similar to svn checkout).
The command format for cloning a warehouse is:
git clone <repo>
If we need to clone to a specified directory, we can use the following command format:
git clone <repo> <directory>
Parameter description:
repo:Git repository.
directory:Local directory.
For example, to clone the Ruby language Git code repository Grit, you can use the following command:
$ git clone git://github.com/schacon/grit.git
After executing this command, a file named It is the directory of grit, which contains a .git directory, which is used to save all downloaded version records.
If you want to define the name of the new project directory yourself, you can specify the new name at the end of the above command:$ git clone git://github.com/schacon/grit.git mygrit