关于git:Git-多用户配置

43次阅读

共计 636 个字符,预计需要花费 2 分钟才能阅读完成。

Git 多用户配置

前言

装置 Git 后会设置一个全局的用户名 / 邮箱,Git 的全局配置保留在 ~/.gitconfig

这样,公司我的项目和集体我的项目的 git commit 信息都会用全局的用户名 / 邮箱,很显著集体我的项目最好不要蕴含公司的任何信息。

那如何独自为我的项目设置的用户名?
能够用 git config user.name "your name" 为我的项目独自设置,也能够用 includeIf 个性为局部我的项目设置

includeIf

Git v2.13 提供 includeIf 条件配置,能够指定某个目录所应用的 gitconfig

首先,创立 .gitconfig-work 文件,用于寄存公司我的项目的目录

# ~/.gitconfig-work
[user]
  name = my work
  email = work@company.net

而后,创立 .gitconfig-me 文件,为寄存集体我的项目的目录

# ~/.gitconfig-me
[user]
  name = my github
  email = me@gmail.net

最初,批改 .gitconfig 文件

# ~/.gitconfig
[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/me/"]
  path = .gitconfig-me

集体我的项目放到 ~/me/ 下,工作我的项目放到 ~/work/,这样就不必每个我的项目独自设置了。

参考

  1. https://stackoverflow.com/que…
正文完
 0