Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git 命令和设置
  6. Git config 命令
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Git config 命令


设置用户名和电子邮件

$ git config --global user.name <username>
$ git config --global user.email <mailaddress>

如果没有--global选项,此设置将仅应用于特定存储库。

彩色显示输出

$ git config --global color.ui auto

为命令设置别名

$ git config --global alias.<aliasname> <commandname>

从版本控制跟踪中删除文件

$ echo <filename> >> .gitignore

.gitignore文件下添加文件路径。Git 将不再管理这些文件。您必须提交.gitignore文件才能发挥作用。

在版本控制下跟踪空目录

$ cd <dirname>
$ touch .gitkeep

Git 不会跟踪空目录。如果您想将其添加到版本控制中,则需要在该目录中放置一个文件。人们通常做的一个常见做法是在空目录中添加一个.gitkeep文件。

显示设置

$ git config --global --list

设置与代理服务器的 HTTP 连接

将以下设置添加到.gitconfig文件的 http 项。

[http]
  proxy = <address of the proxy server>:<port of the proxy server>

您也可以使用以下 config 命令对其进行配置:

$ git config --global http.proxy <address of the proxy server>:<port of the proxy server>

建立到用户认证代理服务器的 HTTP 连接

将以下设置添加到.gitconfig文件的 http 项。

[http]
  proxy = http://<username>:<password>@<address of the proxy server>:<port of the proxy server>

您也可以使用以下 config 命令对其进行配置:

$ git config --global http.proxy http://<username>:<password>@<address of the
  proxy server>:<port of the proxy server>

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life