工具指南|git使用前的基本配置
Git(1)- 使用前的基本配置
为了更好的使用体验 Git,在正式使用 Git 前需要进行一些必要的设置。
设置用户信息
安装完 Git 之后,要做的第一件事就是设置你的用户名和邮件地址。每一个 Git 提交都会使用这些信息,它们会写入到你的每一次提交中,不可更改:
1 | # git config --global user.name "yourname" |
设置行尾首选项
每次按键盘上的 return 时,会插入一个称为行结束符的不可见字符。 不同的操作系统处理行结束符的方式不同。
在使用 Git 和 GitHub 协作处理项目时,Git 可能产生意外结果,例如,您在 Windows 计算机上操作,而您的协作者是在 macOS 中做的更改。
您可以将 Git 配置为自动处理行结束符,以便与使用不同操作系统的人员有效地协作。
1 | git config --global core.autocrlf input |
1 | git config --global core.autocrlf true |
设置默认分支名
分支名默认为 Master ,但是 Github 仓库默认分支名修改为了 main ,由于需要经常使用 Github ,因此修改默认分支名为 main。如果你主要是有 Gitee ,则可以不修改。
1 | # git config --global init.defaultBranch "分支名" |
设置文本编辑器
可以配置一个你熟悉使用的编辑器作为 Git 的默认编辑器,通过下面的指令配置。
1 | # git config --global core.editor "编辑器名" |
检查配置信息
如果想要检查你的配置,可以使用 git config —list 命令来列出所有 Git 当时能找到的配置。
1 | $ git config --list |
当然你也可以在用户目录下的 .gitconfig
文件中查看所有配置。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 wmJim's Blog!
评论