Git 多项目配置

Git 多项目配置

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

有时会在公司的电脑上做一些开源项目,但 git commit 提交的是公司的用户名/邮箱。

那如何设置为自己的用户名?可以用 git config user.name "your name" 为项目单独设置,也可以用 includeIf

includeIf

Git v2.13 提供 includeIf 条件配置,可以指定某个目录所使用的 gitconfig

  1. 修改 .gitconfig 文件
# ~/.gitconfig
[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/me/"]
  path = .gitconfig-me
  1. 为公司项目目录创建 .gitconfig-work 文件
# ~/.gitconfig-work
[user]
  name = my work
  email = work@company.net
  1. 为个人项目目录创建 .gitconfig-me 文件
# ~/.gitconfig-me
[user]
  name = my github
  email = me@gmail.net

开源项目放到 ~/me/ 下,工作项目放到 ~/work/,这样就不用每个项目单独设置了

参考

  1. https://stackoverflow.com/questions/8801729/is-it-possible-to-have-different-git-configuration-for-different-projects

本博客(marsk6)所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

posted @ 2021-08-07 15:39  marsk68  阅读(243)  评论(0编辑  收藏  举报