feat: split git user identity by repo directory

Leave global name/email empty with useConfigOnly so unmatched repos cannot commit. Personal identity applies under ~/.dotfile, ~/code, and ~/.pouch; work identity stays in local ~/.gitconfig.work for ~/workrepo.
This commit is contained in:
2026-09-14 14:55:44 +08:00
parent 097fce7827
commit 0b04a4de50
4 changed files with 35 additions and 3 deletions
+15
View File
@@ -11,6 +11,7 @@ usage() {
备份已有 ~/.gitconfig,软链接到 ~/.dotfile/git/.gitconfig。
同时为 git-credential.sh 添加可执行权限。
若本机还没有 ~/.gitconfig.work,则生成空模板(~/workrepo 公司身份,需自行填写)。
凭据由 ~/.dotfile/git/git-credential.sh 处理(兼容 Git < 2.36,低版本回退 store)。
@@ -41,3 +42,17 @@ fi
chmod +x "$HOME/.dotfile/git/git-credential.sh"
# 兼容旧路径:若仍存在则保持可执行
chmod +x "$HOME/.dotfile/git/git-credential-linux.sh" 2>/dev/null || true
work_cfg="$HOME/.gitconfig.work"
if [ -e "$work_cfg" ]; then
echo " $work_cfg already exists, skip"
else
cat > "$work_cfg" <<'EOF'
# 公司 Git 身份(仅本机,不要提交到 dotfile)
# ~/workrepo 下的仓库会加载本文件。取消注释并填写后再 commit:
# [user]
# name = Your Name
# email = you@company.com
EOF
echo " Created $work_cfg — fill in company user.name / user.email"
fi