我的 Git 初始化配置

我的 Git 初始化配置

安装完 Git 之后,我们需要做一些基础配置,以便后续开心地开发。以下是我会设置的一些基础配置,仅供大家参考。

用户信息

要做的第一件事就是设置你的用户名和邮件地址。这一点很重要,因为每一个 Git 提交都会使用这些信息,它们会写入到你的每一次提交中,不可更改:

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

Git 指令别名

如果不想每次都输入完整的 Git 命令,可以通过 git config 文件来轻松地为每一个命令设置一个别名。

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.ps push
$ git config --global alias.m merge
$ git config --global alias.p pull
$ git config --global alias.l "log --oneline --max-count=10"

除此之外,我还会下载一个 npm 包:git-open,会拓展出一个 git open 指令,用于在浏览器中打开远程仓库。

$ git config --global alias.o open

统一用 LF 行结束符

对于使用多系统(Windows、macOS)开发同一个项目的同学,通常会遇到行结束符(line endings)的问题——Windows 系统使用的是 CRLF(nr),MacOS 系统使用的是 LF(n)。

Git 中是通过 core.autocrlf 来控制的。比较麻烦的是,core.autocrlf 默认取值为 true,Windows 系统下,在提交代码时,会自动将 LF 转换成 CRLF,一旦提交,对使用 Mac 的同学就会带来问题。因此,要把这个默认行为去掉。

$ git config --global core.autocrlf input

检查配置信息

使用 git config --list 命令来列出所有 Git 当时能找到的配置。

$ git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

还可以通过输入 git config <key>:来检查 Git 的某一项配置。

$ git config user.name
John Doe


原文始发于微信公众号(写代码的宝哥):我的 Git 初始化配置

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/243889.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!