1. Initialize the warehouse in the existing directory
If you plan to use Git to manage an existing project, you only need to go to the project directory and enter the following command.
# 初始化仓库$ git init
- This command creates a subdirectory named. Git, which contains all the necessary files in your initialized git repository, which are the backbone of the Git repository. However, at this point, we just do an initialization operation, and the files in your project are not being tracked.
If you are initializing a Git repository for versioning in a folder that already has files (rather than an empty folder), you should start tracking these files and submitting them. You can git add implement a trace of the specified file by command, and then execute the git commit commit.
# 添加所有的 .c 文件# git add [文件名]$ git add *.c# 提交文件到本地仓库# git commit -m [提交内容说明]$ git commit -m "initial project version"
2, cloning the existing warehouse
If you want to get a copy of a Git repository that already exists, you need to use the git clone command. Git clones almost all of the data on the GIT repository server, rather than just copying the files needed to complete your work. When you execute the git clone command, each version of each file in a remote Git repository is pulled down by default.
The command format for the Clone warehouse is git clone [url] . For example, to clone a Git-linked library libgit2, you can use the following command.
# git clone [仓库的 url 地址]$ git clone https://github.com/libgit2/libgit2
- This creates a directory named "Libgit2" under the current directory, and in this directory initializes a. Git folder, pulls all the data from the remote repository into the. git folder, and then reads a copy of the latest version of the file from it.
If you want to customize the name of the local repository when cloning a remote repository, you can use the following command.
# git clone [仓库的 url 地址] [本地仓库名称]$ git clone https://github.com/libgit2/libgit2 mylibgit
- This will perform the same action as the previous command, but the locally created warehouse name becomes Mylibgit.
Git supports a variety of data transfer protocols. The above example uses https:// protocols, but you can also use git:// protocols or SSH transport protocols, for example [email protected]:path/to/repo.git .
IOS-Get Git Repository (Distributed version control system)