惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - nuccch

在Cursor中读取飞书文档 使用GIMP去除水印的有效方法 如何基于VSCode打造Java开发环境 在IDEA中配置注释模板 在Windows中使用Linux系统 树形层级结构的数据库表设计方案 如何理解和认识设计模式 申请Let's Encrypt免费HTTPS证书的方法 DBeaver设置不断开连接 构建工具Gradle入门实践 如何在Maven中排除依赖传递 87键键盘的数字键对应快捷键含义 关于Java JSON库的选择 解决mybatis批量更新慢问题 解决Spring Cloud Gateway中使用CompletableFuture.supplyAsync()执行Feign调用报错 Spring Boot框架中在Controller方法里获取Request和Response对象的2种方式 解读Spring Boot框架中不同位置抛出异常的处理流程 探究Spring Boot框架中访问不存在的接口时触发对error路径的访问 Spring Cloud工程中使用Nacos配置中心的2种方式 Swagger开启账号验证访问
为GIT仓库项目设置独立配置参数
nuccch · 2025-12-26 · via 博客园 - nuccch

在Windows10上禁止将git凭证保存到控制面板的凭据管理器中

在 Windows 10 上彻底禁止 Git 将凭证(账号密码)保存到「控制面板 > 凭据管理器」中,核心是完全禁用 Git 的 credential.helper 凭据辅助配置(尤其是 wincred/manager-core 这类关联 Windows 凭据管理器的选项)。

步骤 1:检查当前凭据配置

git config --list --show-origin | findstr "credential.helper"

输出示例(不同层级的配置位置):

  • file:C:/Users/你的用户名/.gitconfig → 全局配置(最常见);
  • file:.git/config → 单个仓库的本地配置;
  • file:C:/Program Files/Git/etc/gitconfig → 系统级配置(需管理员修改)。

步骤 2:彻底移除 / 禁用所有层级的凭据配置

按「全局 → 本地 → 系统」顺序清理,确保无残留:

  1. 清理「全局配置」(对所有仓库生效,优先级最高)
# 移除全局的凭据辅助配置(推荐)
git config --global --unset-all credential.helper

# 强制置空(兜底,确保无残留)
git config --global credential.helper ""
  1. 清理「单个仓库的本地配置」(若有)

如果仅某个仓库配置了凭据保存,先进入该仓库目录,再执行:

# 替换为你的仓库路径(示例)
cd D:/Projects/your-git-repo
# 移除本地凭据配置
git config --local --unset-all credential.helper
git config --local credential.helper ""
  1. 清理「系统级配置」(需管理员终端)
# 移除系统级凭据配置
git config --system --unset-all credential.helper
# 强制置空
git config --system credential.helper ""

步骤 4:删除已保存的旧凭据(关键)

即使禁用了新凭证保存,已存入凭据管理器的旧凭证仍会生效,需手动删除:

  1. 打开「控制面板」→ 「用户账户」→ 「凭据管理器」;
  2. 切换到「Windows 凭据」标签;
  3. 找到所有以 git: 开头(或关联你的 Git 仓库地址,如 github.com、gitee.com)的凭据;
  4. 点击「删除」,确认移除。

步骤 5:验证禁用效果

运行以下命令,若无credential.helper相关输出(或输出为空),则配置生效:

git config --list | findstr "credential.helper"

设置凭证保存在项目本地

步骤 1:清理之前的配置

先移除之前写错的本地仓库配置,避免残留:

# 进入你的项目目录(替换为实际路径)
cd D:/Projects/your-git-repo

# 彻底删除本地仓库的 credential.helper 错误配置
git config --local --unset-all credential.helper

步骤 2:按终端类型重新正确配置

Windows 下需区分「PowerShell/CMD」和「Git Bash」,两者的引号 / 参数格式不同,分别给出正确命令:

场景 1:使用 PowerShell / CMD(Windows 原生终端)
必须用双引号包裹参数,正确命令:

# 核心正确配置:指定凭证存储到项目.git/credentials
git config --local credential.helper "store --file=.git/credentials"

场景 2:使用 Git Bash(Git 自带终端)
可使用单引号或双引号,正确命令:

# 方式1:单引号(推荐)
git config --local credential.helper 'store --file=.git/credentials'

# 方式2:双引号(也可)
git config --local credential.helper "store --file=.git/credentials"

步骤 3:验证配置是否正确
执行以下命令,检查输出是否和预期一致:

# 查看本地仓库的 credential.helper 配置
git config --local --get credential.helper

设置项目user.name和user.email

Git 的用户信息配置分 3 个层级(优先级:本地 > 全局 > 系统):

  • --local:仅当前项目生效(保存在项目 .git/config 文件中);
  • --global:对当前用户所有项目生效(保存在 C:/Users/你的用户名/.gitconfig);
  • --system:对系统所有用户生效(需管理员,极少用)。

为 Git 项目单独设置user.nameuser.email(仅对当前项目生效,不影响全局 / 其他项目),核心是使用git config --local命令(--local表示「本地仓库级别」,优先级高于全局配置)。

步骤 1:进入目标项目目录

打开 PowerShell/CMD/Git Bash,切换到需要单独配置的 Git 项目根目录(必须确保目录下有 .git 文件夹):

# 示例:替换为你的项目实际路径(PowerShell/CMD)
cd D:/Projects/your-git-repo

# Git Bash 路径写法(示例)
cd /d/Projects/your-git-repo

步骤 2:为当前项目设置专属的user.nameuser.email

执行以下命令,替换为你的自定义用户名和邮箱:

# 设置项目专属的用户名
git config --local user.name "你的项目专属用户名"

# 设置项目专属的邮箱
git config --local user.email "你的项目专属邮箱@xxx.com"

步骤 3:验证配置是否生效

查看当前项目的本地配置,确认user.nameuser.email已正确设置:

# 查看当前项目的所有本地配置(重点看 [user] 段)
git config --local --list

# 或单独查看用户名/邮箱
git config --local user.name
git config --local user.email