【git】修改git凭据

Windows

poweshell 复制代码
# 删除 Windows 凭据
cmdkey /delete:git:https://github.com

# 删除本地 git 配置
git config --global --unset user.name
git config --global --unset user.email

# 设置新的 git 配置(请修改为你的信息)
git config --global user.name "你的新用户名"
git config --global user.email "你的新邮箱"

# 清除 git 缓存的凭据
git config --global --unset credential.helper

# 提示完成
Write-Host "Git 配置已重置,下次push时需要重新输入 GitHub 账号密码" -ForegroundColor Green

Linux

bash 复制代码
#!/bin/bash

# 删除缓存的凭据
git config --global --unset credential.helper
rm -rf ~/.git-credentials

# 清除 SSH 密钥(可选,取消注释如果需要)
# rm -rf ~/.ssh/id_rsa*

# 删除全局 git 配置
git config --global --unset user.name
git config --global --unset user.email

# 设置新的 git 配置
echo "请输入你的 Git 用户名:"
read username
echo "请输入你的 Git 邮箱:"
read email

git config --global user.name "$username"
git config --global user.email "$email"

# 清除本地凭据缓存
git config --global credential.helper cache
git config --global --unset credential.helper

echo -e "\033[32mGit 配置已重置,下次push时需要重新输入 GitHub 账号密码\033[0m"
相关推荐
程序员差不多先生11 小时前
Anthropic 用 5 个月重写了 Git:当 AI Agent 把版本控制系统逼到墙角
人工智能·git·elasticsearch·deepseek v4 pro·kimi k3·glm 5.3·qwen3.7 max
leo_厉锵12 小时前
GIT习题
git
catoop1 天前
用 Shell 包装函数,让单个命令拥有专属配置
git
Zguigo1 天前
学会更高效的理解AI的输出?
人工智能·git·ai
鬼手点金1 天前
上下文:Agent 的眼睛
java·前端·人工智能·git·深度学习
guohuang1 天前
让机器人安全失败:点云中断、TF 超时和控制器崩溃怎么测
git·安全·机器人
小道士写程序1 天前
Git 大文件问题解决办法
git
黑泽明Coding2 天前
如何重置git分支,清空分支所有提交历史
git
小堃学编程2 天前
Git远程开发操作指南
git
于眠牧北2 天前
雷电模拟器9/14搭配charles抓取自带浏览器接口9/14
经验分享·笔记·git