Git create repository

git init

Git uses the  git init  command to initialize a Git repository. Many Git commands need to be run in the Git repository, 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 resource, and other project directories remain unchanged (Git only generates a .git directory in the root directory of the repository).

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

git init

After the command is executed, a .git directory will be generated in the current directory.

Use the directory we specified as the Git repository.

[root@localhost ~]# git init newrepo
Initialized empty Git repository in /root/newrepo/.git/

After initialization, a directory named .git will appear in the newrepo directory, and 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 use the git add command to tell Git to start adding these files, and then commit:

[root@localhost newrepo]# git add test.c
[root@localhost newrepo]# git commit -m 'first project'
[master (root-commit) afe659f] first project
 1 file changed, 4 insertions(+)
 create mode 100644 test.c

The above command submits the test.c file in the directory to the warehouse.


git clone

Use  git clone  to copy a project from an existing Git repository.

The command format for cloning a repository 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 repository Grit, use the following command:

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

After executing this command, a directory named grit will be created in the current directory, which contains a .git directory for saving all downloaded version records.

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

 

[root@localhost ~]# git clone git://github.com/schacon/grit.git mygrit
Cloning into 'mygrit'...
remote: Counting objects: 4051, done.
remote: Total 4051 (delta 0), reused 0 (delta 0), pack-reused 4051
Receiving objects: 100% (4051/4051), 2.03 MiB | 8.00 KiB/s, done.
Resolving deltas: 100% (1467/1467), done.

下载结果



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570643&siteId=291194637