Git自动切换提交时使用的用户名

根据远程地址自动切换commit时候使用的用户名。比如一般都是使用下面nickname提交,但如果待提交仓库包含ssh://git@you-company.com/**这样的远程地址,则自动使用MY_NAME进行commit

先找到.gitconfig文件位置

git config --origin --list

编辑.gitconfig,增加includeIf段的内容

.gitconfig

[user]
	name = nickname
	email = nickname@gmail.com
[credential]
	helper = manager-core
[ssh]
	variant = ssh
[core]
	preloadindex = true
	fscache = true
	editor = vim
	autocrlf = true
[gc]
	auto = 256

[includeIf "hasconfig:remote.*.url:ssh://git@you-company.com/**"]
	path = .gitconfig-company

在当前.gitconfig同级目录下新建文件.gitconfig-company,输入在公司使用的名字。

.gitconfig-company

[user]
	name = MY_NAME
	email = MY_NAME@company.com
posted @ 2024-03-13 14:46  小小记录本  阅读(15)  评论(0编辑  收藏  举报