[TOC] #### 1. git init 介绍 --- `git init` 命令用于初始化仓库,也就是让 git 对当前目录中的内容进行版本控制 这个命令是每个人刚学习 git 时最先接触的命令,本文将围绕该命令引出一些相关的内容 #### 2. git init 干了什么 --- 通过下图可看到,使用 git init 初始化仓库后在当前目录下创建了一个 .git 目录,这个目录就是 git 的版本库  在上图中可以看到有不少行的黄色字体 ``` hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> ``` ``` 提示: 使用 master 分支作为初识分支的名称。这是默认的分支名称 提示: 初识分支名可能会发生变化,这个是可配置的 提示: 如果你创建新的存储库时,不想出现该提示,可执行: git config --global init.defaultBranch <name> 分支名称不是 “master”,而是 “main”、“trunk”、“master”、"development" 时,可以通过以下命令重命名刚才创建的分支: git branch -m <name> ``` 当我们不想每次初始化仓库时都出现 hint 提示时,可以设置默认分支名 ``` git config --global init.defaultBranch master ``` 上面设置的全局默认分支可以通过以下命令查看 ``` git config --global --list ``` 取消默认分支设置 ``` git config --global --unset init.defaultBranch ``` #### 3. git init 初始化仓库 --- 初始化仓库命令格式: ``` git init [<directory>] ``` 创建版本库使用示例: ``` # 在当前目录下初始化仓库 git init # 在指定目录下初始化仓库,当目录不存在时会自动创建 git init <directory> ``` #### 4. git init 命令参数 --- `-b, --initial-branch`: 我们也可以在初始化仓库时指定分支名 ``` git init -b <name> ``` 将当前分支重命名为 liang ``` git branch -m <name> ```