Latest web development tutorials

Create Git repository

This chapter we will introduce how to create a Git repository.

You can use an existing directory as a Git repository.


git init

Git usinggit init command to initialize a Git repository, Git many commands are required to run the Git repository, so git initis the first to use Git command.

After the execution is completegit init command, Git repository will generate a .git directory that contains all the metadata of resources, other projects directory unchanged (unlike SVN generates .svn directory in each subdirectory, Git only in warehouse generation .git directory in the root directory).

Instructions

Git repository as the current directory, we only need to initialize it.

git init

After executing this command will generate a .git directory in the current directory.

We use the specified directory as a Git repository.

git init newrepo

After initialization, it will be a directory called .git at newrepo directories, data, and resources all Git needs are stored in this directory.

If you want to have several files under version control, you need to use git add command to tell Git began tracking those files, and then submit the current directory:

$ git add *.c
$ git add README
$ git commit -m '初始化项目版本'

The above command directory that end with .c and README files to the repository.


git clone

We usegit clone copy from an existing Git repository project (similar to svn checkout).

Clone repository command format is:

git clone <repo>

If we need to clone to a specific directory, you 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 the command, create a directory in the current directory called grit, which contains a .git directory for storing all downloaded version records.

If you want to define your own new project directory name, you can specify a new name at the end of the above command:

$ git clone git://github.com/schacon/grit.git mygrit